function goTo (url) {
    window.location = url;
}

function button_on (imgId) {
    if ( document.images ) {
        butOn = eval ( imgId + "_on.src" );
        document.getElementById(imgId).src = butOn;
    }
}

function button_off (imgId) {
    if (document.images) {
        butOff = eval ( imgId + "_off.src" );
        document.getElementById(imgId).src = butOff;
    }
}


function activateTopMenuButton (buttonId) {
    dojo.byId(buttonId).style.backgroundColor = "#EEEEEE";
    dojo.byId(buttonId).style.color = "#000000";
}

function deactivateTopMenuButton (buttonId) {
    dojo.byId(buttonId).style.backgroundColor = "";
    dojo.byId(buttonId).style.color = "#FFFFFF";
}

function activateLeftMenuButton (buttonId) {
    dojo.byId(buttonId).style.backgroundColor = "#AAAAAA";
//dojo.byId(buttonId).style.color = "#000000";
}

function deactivateLeftMenuButton (buttonId) {
    dojo.byId(buttonId).style.backgroundColor = "#686C7A";
//dojo.byId(buttonId).style.color = "#686C7A";
}

function manageDisclaimerApproval () {
    if (dijit.byId("disclaimer").attr("checked")) {
        dojo.byId("searchConsultantButtonArea").innerHTML = '<img src="images/buttons/Search_public_registry_out.png" style="cursor:pointer;" id="searchPublicRegistryButtonImage" name="searchPublicRegistryButtonImage" onmouseout="button_off(\'searchPublicRegistryButtonImage\');" onmouseover="button_on(\'searchPublicRegistryButtonImage\');" onclick="accessToPublicRegistrySearch();" alt="Search_public_registry_out"/>';
        dojo.byId("logInCreateAccountButtonArea").innerHTML = '<img src="images/buttons/Login_or_create_account_out.png" style="cursor:pointer;" id="loginCreateAccountButtonImage" name="loginCreateAccountButtonImage" onmouseout="button_off(\'loginCreateAccountButtonImage\');" onmouseover="button_on(\'loginCreateAccountButtonImage\');" onclick="accessToLoginCreateAccount();" alt="Login_or_create_account_out"/>';
    } else {
        dojo.byId("searchConsultantButtonArea").innerHTML = '<img src="images/buttons/Search_public_registry_inactive.png" alt="Search_public_registry_inactive"/>';
        dojo.byId("logInCreateAccountButtonArea").innerHTML = '<img src="images/buttons/Login_or_create_account_inactive.png" alt="Login_or_create_account_inactive"/>';
    }
}

function accessToPublicRegistrySearch () {
    document.searchConsultantForm.submit();
}

function accessToLoginCreateAccount () {
    document.logInCreateAccountForm.submit();
}

function showLogInAccountFormArea () {
    dijit.byId("createAccountForm").reset();
    document.getElementById("createAccountFormStatusMessage").setAttribute("class", "");
    document.getElementById("createAccountFormStatusMessage").setAttribute("className", "");
    dojo.byId("createAccountFormStatusMessage").innerHTML = "";

    dojo.byId("logInAccountFormArea").style.backgroundColor = "#F2F5F9";
    dojo.byId('logInAccountFormArea').style.display = "";
    dojo.byId('logInAccountQuestionArea').style.display = "none";
    dojo.byId("logInAccountQuestionArea").style.backgroundColor = "#EEEEEE";
    dojo.byId('createAccountQuestionArea').style.display = "";
    dojo.byId("createAccountQuestionArea").style.backgroundColor = "#EEEEEE";
    dojo.byId('createAccountFormArea').style.display = "none";
    dojo.byId("createAccountFormArea").style.backgroundColor = "#EEEEEE";
}

function showCreateAccountFormArea () {
    dijit.byId("logInAccountForm").reset();
    document.getElementById("logInAccountFormStatusMessage").setAttribute("class", "");
    document.getElementById("logInAccountFormStatusMessage").setAttribute("className", "");
    dojo.byId("logInAccountFormStatusMessage").innerHTML = "";

    dojo.byId("logInAccountFormArea").style.backgroundColor = "#EEEEEE";
    dojo.byId('logInAccountFormArea').style.display = "none";
    dojo.byId('logInAccountQuestionArea').style.display = "";
    dojo.byId("logInAccountQuestionArea").style.backgroundColor = "#EEEEEE";
    dojo.byId('createAccountQuestionArea').style.display = "none";
    dojo.byId("createAccountQuestionArea").style.backgroundColor = "#EEEEEE";
    dojo.byId('createAccountFormArea').style.display = "";
    dojo.byId("createAccountFormArea").style.backgroundColor = "#F2F5F9";
}

function activateLogInAccountQuestionArea () {
    dojo.byId("logInAccountQuestionArea").style.backgroundColor = "#F2F5F9";
}

function deactivateLogInAccountQuestionArea () {
    dojo.byId("logInAccountQuestionArea").style.backgroundColor = "#EEEEEE";
}

function activateCreateAccountQuestionArea () {
    dojo.byId("createAccountQuestionArea").style.backgroundColor = "#F2F5F9";
}

function deactivateCreateAccountQuestionArea () {
    dojo.byId("createAccountQuestionArea").style.backgroundColor = "#EEEEEE";
}

function clearLogInAccountForm () {
    document.getElementById("logInAccountFormStatusMessage").setAttribute("class", "");
    document.getElementById("logInAccountFormStatusMessage").setAttribute("className", "");
    dojo.byId("logInAccountFormStatusMessage").innerHTML = "";
}

function clearCreateAccountForm () {
    document.getElementById("createAccountFormStatusMessage").setAttribute("class", "");
    document.getElementById("createAccountFormStatusMessage").setAttribute("className", "");
    dojo.byId("createAccountFormStatusMessage").innerHTML = "";
}

function isEmailUnique () {
    document.getElementById("createAccountFormStatusMessage").setAttribute("class", "formProcessingRequestMessage");
    document.getElementById("createAccountFormStatusMessage").setAttribute("className", "formProcessingRequestMessage");
    dojo.byId("createAccountFormStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0' style='margin-left:auto;margin-right:auto;'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:10px;font-weight:bold;'>Your request is being processed...</td></tr></table>";
    
    dojo.byId("logInAccountQuestionArea").onclick = function () {};
    dojo.byId("logInAccountQuestionArea").onmouseover = function () {};
    dojo.byId("logInAccountQuestionArea").style.cursor = "wait";

    if (!dijit.byId("firstName").isValid() ||
        !dijit.byId("lastName").isValid() ||
        !dijit.byId("email").isValid() ||
        !dijit.byId("password").isValid() ||
        !dijit.byId("confirmationPassword").isValid()) {
        dijit.byId("firstName").focus();
        dijit.byId("lastName").focus();
        dijit.byId("email").focus();
        dijit.byId("password").focus();
        dijit.byId("confirmationPassword").focus();
        dijit.byId("resetCreateAccount").focus();
        document.getElementById("createAccountFormStatusMessage").setAttribute("class", "formErrorMessage");
        document.getElementById("createAccountFormStatusMessage").setAttribute("className", "formErrorMessage");
        dojo.byId("createAccountFormStatusMessage").innerHTML = "Invalid Paramenter(s)";
        dojo.byId("logInAccountQuestionArea").onclick = showLogInAccountFormArea;
        dojo.byId("logInAccountQuestionArea").onmouseover = activateLogInAccountQuestionArea;
        dojo.byId("logInAccountQuestionArea").style.cursor = "pointer";
    } else {
        dijit.byId("resetCreateAccount").attr("disabled", true);
        dijit.byId("createAccount").attr("disabled", true);
        dojo.xhrPost({
            url: "ajaxValidateEmailUniqueness.php",
            form: 'createAccountForm',
            timeoutSeconds: 500000,
            load: function(response, ioArgs) {
                if(response == '1') {
                    dijit.byId("createAccountForm").submit();
                } else if (response == "DuplicatedEmailException") {
                    document.getElementById("createAccountFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("createAccountFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("createAccountFormStatusMessage").innerHTML = "An account already exists using the email specified.";
                    dijit.byId("resetCreateAccount").attr("disabled", false);
                    dijit.byId("createAccount").attr("disabled", false);
                    dojo.byId("logInAccountQuestionArea").onclick = showLogInAccountFormArea;
                    dojo.byId("logInAccountQuestionArea").onmouseover = activateLogInAccountQuestionArea;
                    dojo.byId("logInAccountQuestionArea").style.cursor = "pointer";
                } else {
                    document.getElementById("createAccountFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("createAccountFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("createAccountFormStatusMessage").innerHTML = "Error!!";
                    dijit.byId("resetCreateAccount").attr("disabled", false);
                    dijit.byId("createAccount").attr("disabled", false);
                    dojo.byId("logInAccountQuestionArea").onclick = showLogInAccountFormArea;
                    dojo.byId("logInAccountQuestionArea").onmouseover = activateLogInAccountQuestionArea;
                    dojo.byId("logInAccountQuestionArea").style.cursor = "pointer";
                }
                return response;
            },
            error: function(response, ioArgs) {
                alert("ERROR!!!!");
                return response;
            }
        });
    }
}

function isValidUserLogIn () {

    document.getElementById("logInAccountFormStatusMessage").setAttribute("class", "formProcessingRequestMessage");
    document.getElementById("logInAccountFormStatusMessage").setAttribute("className", "formProcessingRequestMessage");
    dojo.byId("logInAccountFormStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0' style='margin-left:auto;margin-right:auto;'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:10px;font-weight:bold;'>Your request is being processed...</td></tr></table>";

    dojo.byId("createAccountQuestionArea").onclick = function () {};
    dojo.byId("createAccountQuestionArea").onmouseover = function () {};
    dojo.byId("createAccountQuestionArea").style.cursor = "wait";

    if (!dijit.byId("username").isValid() || !dijit.byId("logInPassword").isValid()) {
        dijit.byId("username").focus();
        dijit.byId("logInPassword").focus();
        dijit.byId("resetLogInAccount").focus();
        document.getElementById("logInAccountFormStatusMessage").setAttribute("class", "formErrorMessage");
        document.getElementById("logInAccountFormStatusMessage").setAttribute("className", "formErrorMessage");
        dojo.byId("logInAccountFormStatusMessage").innerHTML = "Invalid fields(s) entered.";
        dojo.byId("createAccountQuestionArea").onclick = showCreateAccountFormArea;
        dojo.byId("createAccountQuestionArea").onmouseover = activateCreateAccountQuestionArea;
        dojo.byId("createAccountQuestionArea").style.cursor = "pointer";
    } else {
        dijit.byId("resetLogInAccount").attr("disabled", true);
        dijit.byId("logInAccount").attr("disabled", true);
        dojo.xhrPost({
            url: "ajaxValidateUserLogIn.php",
            form: 'logInAccountForm',
            timeoutSeconds: 500000,
            load: function(response, ioArgs) {
                if(response == '1') {
                    dijit.byId("logInAccountForm").submit();
                } else if (response == "InvalidLoginException") {
                    document.getElementById("logInAccountFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("logInAccountFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("logInAccountFormStatusMessage").innerHTML = "Invalid password entered.";
                    dijit.byId("resetLogInAccount").attr("disabled", false);
                    dijit.byId("logInAccount").attr("disabled", false);
                    dojo.byId("createAccountQuestionArea").onclick = showCreateAccountFormArea;
                    dojo.byId("createAccountQuestionArea").onmouseover = activateCreateAccountQuestionArea;
                    dojo.byId("createAccountQuestionArea").style.cursor = "pointer";
                } else if (response == "EmailDoesNotExistException") {
                    document.getElementById("logInAccountFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("logInAccountFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("logInAccountFormStatusMessage").innerHTML = "Specified email cannot be found.";
                    dijit.byId("resetLogInAccount").attr("disabled", false);
                    dijit.byId("logInAccount").attr("disabled", false);
                    dojo.byId("createAccountQuestionArea").onclick = showCreateAccountFormArea;
                    dojo.byId("createAccountQuestionArea").onmouseover = activateCreateAccountQuestionArea;
                    dojo.byId("createAccountQuestionArea").style.cursor = "pointer";
                } else {
                    document.getElementById("logInAccountFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("logInAccountFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("logInAccountFormStatusMessage").innerHTML = "An error has occurred. Please try again.";
                    dijit.byId("resetLogInAccount").attr("disabled", false);
                    dijit.byId("logInAccount").attr("disabled", false);
                    dojo.byId("createAccountQuestionArea").onclick = showCreateAccountFormArea;
                    dojo.byId("createAccountQuestionArea").onmouseover = activateCreateAccountQuestionArea;
                    dojo.byId("createAccountQuestionArea").style.cursor = "pointer";
                }
                return response;
            },
            error: function(response, ioArgs) {
                alert("ERROR!!!!");
                return response;
            }
        });
    }
        
}

function showPasswordRecoveryForm() {
    document.body.style.overflow = "hidden";
    dijit.byId('passwordRecoveryDialog').show();
}

function submitPasswordRecoveryForm () {
    document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("class", "formProcessingRequestMessage");
    document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("className", "formProcessingRequestMessage");
    dojo.byId("passwordRecoveryFormStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0' style='margin-left:auto;margin-right:auto;'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:10px;font-weight:bold;'>Your request is being processed...</td></tr></table>";

    if (!dijit.byId("recoveryEmail").isValid()) {
        dijit.byId("recoveryEmail").focus();
        
        document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("class", "formErrorMessage");
        document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("className", "formErrorMessage");
        dojo.byId("passwordRecoveryFormStatusMessage").innerHTML = "Invalid Paramenter(s)";
    } else {
        dijit.byId("resetPasswordRecoveryForm").attr("disabled", true);
        dijit.byId("submitPasswordRecoveryForm").attr("disabled", true);
        dojo.xhrPost({
            url: "ajaxSendPasswordRecoveryEmail.php",
            form: 'passwordRecoveryForm',
            timeoutSeconds: 500000,
            load: function(response, ioArgs) {
                if(response == '1') {
                    //Show Success Message
                    dojo.byId('passwordRecoveryFormArea').style.display = "none";
                    dojo.byId('passwordRecoveryConfirmationArea').style.display = "";
                    dojo.byId('recoveryEmailConfirmationArea').innerHTML = dijit.byId("recoveryEmail").attr("value");
                } else if (response == "EmailDoesNotExistException") {
                    document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("passwordRecoveryFormStatusMessage").innerHTML = "Specified email cannot be found.";
                    dijit.byId("resetPasswordRecoveryForm").attr("disabled", false);
                    dijit.byId("submitPasswordRecoveryForm").attr("disabled", false);
                }else {
                    //Show Error Message
                    document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("passwordRecoveryFormStatusMessage").innerHTML = "An error has occurred. Please try again.";
                    dijit.byId("resetPasswordRecoveryForm").attr("disabled", false);
                    dijit.byId("submitPasswordRecoveryForm").attr("disabled", false);
                }
                return response;
            },
            error: function(response, ioArgs) {
                alert("ERROR!!!!");
                return response;
            }
        });
    }
}

function clearPasswordRecoveryForm () {
    dijit.byId("passwordRecoveryForm").reset();
    dijit.byId("resetPasswordRecoveryForm").attr("disabled", false);
    dijit.byId("submitPasswordRecoveryForm").attr("disabled", false);
    document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("class", "");
    document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("className", "");
    dojo.byId("passwordRecoveryFormStatusMessage").innerHTML = "";
    dojo.byId('recoveryEmailConfirmationArea').innerHTML = "";
}

function closeRecoveryPasswordDialog () {
    document.body.style.overflow = "";
    dijit.byId("passwordRecoveryDialog").hide();
    dojo.byId('passwordRecoveryFormArea').style.display = "";
    dojo.byId('passwordRecoveryConfirmationArea').style.display = "none";
    dijit.byId("passwordRecoveryForm").reset();
    dijit.byId("resetPasswordRecoveryForm").attr("disabled", false);
    dijit.byId("submitPasswordRecoveryForm").attr("disabled", false);
    document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("class", "");
    document.getElementById("passwordRecoveryFormStatusMessage").setAttribute("className", "");
    dojo.byId("passwordRecoveryFormStatusMessage").innerHTML = "";
    dojo.byId('recoveryEmailConfirmationArea').innerHTML = "";
}

function manageServingSince () {
    if (dijit.byId("serviceId").attr('value') > 0) {
        dijit.byId("servingSinceMonth").attr("disabled", false);
        dijit.byId("servingSinceYear").attr("disabled", false);
        dijit.byId("addServiceProvided").attr("disabled", false);
    } else {
        dijit.byId("servingSinceMonth").attr("disabled", true);
        dijit.byId("servingSinceYear").attr("disabled", true);
        dijit.byId("addServiceProvided").attr("disabled", true);
        dijit.byId("servingSinceMonth").reset();
        dijit.byId("servingSinceYear").reset();
    }
}

function addServiceProvided () {
    try {
        
        if (!dijit.byId("serviceId").isValid() || 
            !(dijit.byId("servingSinceMonth").attr("value") > 0) ||
            !(dijit.byId("servingSinceYear").attr("value") > 0)) {
            throw "InvalidSelectionException";
        }
        var currentDate = new Date();
        var currentYear = currentDate.getYear();
        if(currentYear < 1000) {
            currentYear += 1900;
        }
        if ((dijit.byId("servingSinceYear").attr("value") < 1900) || (dijit.byId("servingSinceYear").attr("value") > currentYear)) {
            throw "InvalidServingSinceYearException";
        }
        
        var serviceId = dijit.byId("serviceId").attr('value');
        var serviceName = dijit.byId("serviceId").attr('displayedValue');
        var servingSinceMonthYear = dijit.byId("servingSinceMonth").attr('displayedValue') + ", " +  dijit.byId("servingSinceYear").attr('value')

        verifyServiceProvidedUniqueness(serviceId);

        var newService = {
            id: serviceId,
            service: serviceName,
            servingSince: servingSinceMonthYear
        };

        consultantServicesProvidedStore.newItem(newService);

    } catch (e) {
        if (e == "InvalidSelectionException") {
            alert("You must select or enter a valid Service, Month, and Year in order to add a service to your profile.\nPlease, try again.");
        } else if (e == "DuplicateException") {
            alert("Duplicate Service");
        } else if (e == "InvalidServingSinceYearException") {
            alert("You must select or enter a valid Year (between 1900 and " + currentYear + ") in order to add a service to your profile.\nPlease, try again.");
        }
    }

    consultantServicesProvidedStore.save({
        onComplete: addServiceProvidedDone,
        onError: addServiceProvidedFailed
    });

    dijit.byId("serviceId").reset();
    dijit.byId("servingSinceMonth").reset();
    dijit.byId("servingSinceYear").reset();
    dijit.byId("servicesOfferedDescription").attr("disabled", false);
    
}

function addServiceProvidedDone () {

}

function addServiceProvidedFailed () {

}

function verifyServiceProvidedUniqueness (serviceId) {
    consultantServicesProvidedStore.fetch({
        query: {
            id: serviceId
        },
        queryOptions: {
            ignoreCase: true
        },
        onComplete: isServiceprovidedUnique
    });
}

function isServiceprovidedUnique (items, request) {
    if (items.length > 0) {
        throw "DuplicateException";
    }
}

function deleteServiceProvidedSelected () {
    
    if (isLastServiceProvided()) {
        var answer = confirm("By deleting all of your service categories\nyour services description will be deleted as well.\n\nAre you sure you want to delete this information?");
        if (!answer) {
            return true;
        } else {
            dojo.byId("servicesOfferedDescription").innerHTML = "";
            verifyServicesOfferedDescription();
            dijit.byId("servicesOfferedDescription").attr("disabled", true);
        }
    }

    var items = consultantServicesProvidedGrid.selection.getSelected();
    if(items.length){
        dojo.forEach(items, function(selectedItem) {
            if(selectedItem !== null) {
                consultantServicesProvidedStore.deleteItem(selectedItem);
            }
        });
    }
    consultantServicesProvidedStore.save({
        onComplete: addServiceProvidedDone,
        onError: addServiceProvidedFailed
    });

//activateMakeProfilePublic();
    return true;
}

function isLastServiceProvided () {
    var isLastServiceProvided = true;

    var i = 0;
    var specialtyAreaList = consultantServicesProvidedStore._arrayOfAllItems;
    if(specialtyAreaList.length) {
        dojo.forEach(specialtyAreaList, function(selectedItem) {
            if(selectedItem !== null) {
                dojo.forEach(consultantServicesProvidedGrid.store.getAttributes(selectedItem), function(attribute) {
                    var value = consultantServicesProvidedGrid.store.getValues(selectedItem, attribute);
                    if (attribute == "id") {
                    //parameters = parameters + value;
                    } else if (attribute == "servingSince") {
                        //parameters = parameters + '-'+value+'&';
                        i++;
                    }
                });
            }
        });
    }

    if (i > 1) {
        isLastServiceProvided = false;
    }

    return isLastServiceProvided;
}

function verifyBackgroundDescription () {
    var charLeft = 1000 - dojo.byId("backgroundDescription").value.length;
    if (charLeft < 0) {
        charLeft = 0;
    }
    dojo.byId("backgroundDescriptionCharCounter").innerHTML = "(" + charLeft + " characters left)";
    if (dojo.byId("backgroundDescription").value.length > 1000) {
        dojo.byId("backgroundDescription").value = dojo.byId("backgroundDescription").value.substring(0, dojo.byId("backgroundDescription").value.length - (dojo.byId("backgroundDescription").value.length - 1000));
    }
}

function verifyEducationDescription () {
    var charLeft = 1000 - dojo.byId("educationDescription").value.length;
    if (charLeft < 0) {
        charLeft = 0;
    }
    dojo.byId("educationDescriptionCharCounter").innerHTML = "(" + charLeft + " characters left)";
    if (dojo.byId("educationDescription").value.length > 1000) {
        dojo.byId("educationDescription").value = dojo.byId("educationDescription").value.substring(0, dojo.byId("educationDescription").value.length - (dojo.byId("educationDescription").value.length - 1000));
    }
}

function verifyExperienceDescription () {
    var charLeft = 1000 - dojo.byId("experienceDescription").value.length;
    if (charLeft < 0) {
        charLeft = 0;
    }
    dojo.byId("experienceDescriptionCharCounter").innerHTML = "(" + charLeft + " characters left)";
    if (dojo.byId("experienceDescription").value.length > 1000) {
        dojo.byId("experienceDescription").value = dojo.byId("experienceDescription").value.substring(0, dojo.byId("experienceDescription").value.length - (dojo.byId("experienceDescription").value.length - 1000));
    }
}

function verifyServicesOfferedDescription () {
    var charLeft = 1000 - dojo.byId("servicesOfferedDescription").value.length;
    if (charLeft < 0) {
        charLeft = 0;
    }
    dojo.byId("servicesOfferedDescriptionCharCounter").innerHTML = "(" + charLeft + " characters left)";
    if (dojo.byId("servicesOfferedDescription").value.length > 1000) {
        dojo.byId("servicesOfferedDescription").value = dojo.byId("servicesOfferedDescription").value.substring(0, dojo.byId("servicesOfferedDescription").value.length - (dojo.byId("servicesOfferedDescription").value.length - 1000));
    }
}

function verifyMakeProfilePublic () {
    if (dijit.byId("profileSubmittedIndicator").attr("checked") == true) {
        dijit.byId("verifyMakeProfilePublicDialog").show();
    }
}

function profileNameSameAsOnAccount () {
    dijit.byId("firstName").attr("value", dojo.byId("accountFirstName").value);
    dijit.byId("lastName").attr("value", dojo.byId("accountLastName").value);
}

function profileEmailSameAsOnAccount () {
    dijit.byId("email").attr("value", dojo.byId("accountEmail").value);
}

function physicalAddressSameAsMailingAddress () {
    dijit.byId("physicalAddress").attr("value", dijit.byId("mailingAddress").attr("value"));
    dijit.byId("physicalCity").attr("value", dijit.byId("mailingCity").attr("value"));
    dijit.byId("physicalStateId").attr("value", dijit.byId("mailingStateId").attr("value"));
    dijit.byId("physicalZipCode").attr("value", dijit.byId("mailingZipCode").attr("value"));
}

/*
function activateMakeProfilePublic () {
    if (isUserProfileSubmissionValid()) {
        dijit.byId("profileSubmittedIndicator").attr("disabled", false);
    } else {
        dijit.byId("profileSubmittedIndicator").attr("disabled", true);
        dijit.byId("profileSubmittedIndicator").attr("checked", false);
    }
}
*/

function isUserProfileSubmissionValid () {
    var isUserProfileSubmissionValid = true;
    if (!dijit.byId("firstName").isValid() || (dijit.byId("firstName").attr("value").length == 0)) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("lastName").isValid() || (dijit.byId("lastName").attr("value").length == 0)) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("companyName").isValid() || (dijit.byId("companyName").attr("value").length == 0)) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("physicalAddress").isValid()) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("physicalCity").isValid()) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("physicalStateId").isValid()) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("physicalZipCode").isValid()) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("mailingAddress").isValid() || (dijit.byId("mailingAddress").attr("value").length == 0)) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("mailingCity").isValid() || (dijit.byId("mailingCity").attr("value").length == 0)) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("mailingStateId").isValid() || !(dijit.byId("mailingStateId").attr("value") > 0)) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("mailingZipCode").isValid() || (dijit.byId("mailingZipCode").attr("value").length == 0)) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("telephone").isValid() || (dijit.byId("telephone").attr("value").length == 0)) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("telephoneExt").isValid()) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("cellphone").isValid()) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("email").isValid() || (dijit.byId("email").attr("value").length == 0)) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("website").isValid()) {
        isUserProfileSubmissionValid = false;
    }
    if (!isServiceProvidedListValid()) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("k12ClienteleIndicator").attr("checked") && !dijit.byId("higherEducationClienteleIndicator").attr("checked")) {
        isUserProfileSubmissionValid = false;
    }
    if (dojo.byId("backgroundDescription").value.length == 0) {
        isUserProfileSubmissionValid = false;
    }
    if (dojo.byId("educationDescription").value.length == 0) {
        isUserProfileSubmissionValid = false;
    }
    if (dojo.byId("experienceDescription").value.length == 0) {
        isUserProfileSubmissionValid = false;
    }
    if (!dijit.byId("complaintIndicator").attr("checked") && !dijit.byId("pendingLitigationIndicator").attr("checked") && !dijit.byId("noneIndicator").attr("checked")) {
        isUserProfileSubmissionValid = false;
    }
    return isUserProfileSubmissionValid;
}

/*
function cancelPublishProfile () {
    dijit.byId("verifyMakeProfilePublicDialog").hide();
    dijit.byId("profileSubmittedIndicator").attr("checked", false);
}

function acceptPublishProfile () {
    dijit.byId("verifyMakeProfilePublicDialog").hide();
}
*/

function manageNoneIndicator () {
    if (dijit.byId("noneIndicator").attr("checked") == true) {
        dijit.byId("complaintIndicator").attr("checked" , false);
        dijit.byId("pendingLitigationIndicator").attr("checked" , false);
        dijit.byId("complaintIndicator").attr("disabled" , true);
        dijit.byId("pendingLitigationIndicator").attr("disabled" , true);
    } else {
        dijit.byId("complaintIndicator").attr("disabled" , false);
        dijit.byId("pendingLitigationIndicator").attr("disabled" , false);
    }
}

function startUpdateUserProfileProcess () {
    if (!isUserProfileFormValid()) {
        dojo.byId('userProfileFormStatus').style.display = "";
        document.getElementById("userProfileFormStatus").setAttribute("class", "userProfileFormErrorMessage");
        document.getElementById("userProfileFormStatus").setAttribute("className", "userProfileFormErrorMessage");
        dojo.byId("userProfileFormStatusMessage").innerHTML = "Invalid Parameter(s). Please verify the information provided.";
    } else {
        document.body.style.overflow = "hidden";
        dijit.byId("updateUserProfileDialog").show();
        if (isUserProfileSubmissionValid()) {
            dojo.byId("updateUserProfileValidSubmissionFormArea").style.display = "";
            dojo.byId("updateUserProfileInvalidSubmissionFormArea").style.display = "none";
            dojo.byId("updateUserProfileInvalidSubmissionRemovalFormArea").style.display = "none";
            dojo.byId("updateUserProfileConfirmationArea").style.display = "none";

        } else {
            if (dojo.byId("currentProfileSubmittedIndicator").value == "1") {
                dojo.byId("updateUserProfileValidSubmissionFormArea").style.display = "none";
                dojo.byId("updateUserProfileInvalidSubmissionFormArea").style.display = "none";
                dojo.byId("updateUserProfileInvalidSubmissionRemovalFormArea").style.display = "";
                dojo.byId("updateUserProfileConfirmationArea").style.display = "none";
            } else {
                dojo.byId("updateUserProfileValidSubmissionFormArea").style.display = "none";
                dojo.byId("updateUserProfileInvalidSubmissionFormArea").style.display = "";
                dojo.byId("updateUserProfileInvalidSubmissionRemovalFormArea").style.display = "none";
                dojo.byId("updateUserProfileConfirmationArea").style.display = "none";
            }
        }
    }
}

function submitUserProfileForm (updateType) {

    dojo.byId('userProfileFormStatus').style.display = "";
    document.getElementById("userProfileFormStatus").setAttribute("class", "userProfileFormProcessingRequestMessage");
    document.getElementById("userProfileFormStatus").setAttribute("className", "userProfileFormProcessingRequestMessage");
    dojo.byId("userProfileFormStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:12px;font-weight:bold;'>Saving Information...</td></tr></table>";

    dijit.byId("resetUserProfileForm").attr("disabled", true);
    dijit.byId("submitUserProfileForm").attr("disabled", true);
    dijit.byId("submitUserProfileForm2").attr("disabled", true);

    if (updateType == 0) {
        document.getElementById("updateUserProfileFormStatusMessage0").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("updateUserProfileFormStatusMessage0").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("updateUserProfileFormStatusMessage0").innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:10px;font-weight:bold;'>Your request is being processed...</td></tr></table>";

        dojo.byId("profileSubmittedIndicator").value = (dijit.byId("tempProfileSubmittedIndicator").attr("checked")) ? 1 : 0;

        dijit.byId("resetUpdateUserProfileForm0").attr("disabled", true);
        dijit.byId("submitUpdateUserProfileForm0").attr("disabled", true);

    } else if (updateType == 1) {
        document.getElementById("updateUserProfileFormStatusMessage1").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("updateUserProfileFormStatusMessage1").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("updateUserProfileFormStatusMessage1").innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:10px;font-weight:bold;'>Your request is being processed...</td></tr></table>";

        dojo.byId("profileSubmittedIndicator").value = 0;

        dijit.byId("verifyInvalidFieldsButton").attr("disabled", true);
        dijit.byId("cancelUpdateUserProfileForm1").attr("disabled", true);
        dijit.byId("submitUpdateUserProfileForm1").attr("disabled", true);

    } else if (updateType == 2) {
        document.getElementById("updateUserProfileFormStatusMessage2").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("updateUserProfileFormStatusMessage2").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("updateUserProfileFormStatusMessage2").innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:10px;font-weight:bold;'>Your request is being processed...</td></tr></table>";
        
        dojo.byId("profileSubmittedIndicator").value = 0;

        dijit.byId("verifyInvalidFieldsButton2").attr("disabled", true);
        dijit.byId("resetUpdateUserProfileForm2").attr("disabled", true);
        dijit.byId("submitUpdateUserProfileForm2").attr("disabled", true);

    }
    
    document.getElementById("userServicesProvidedString").value = getUserServicesProvidedString();
    
    dojo.xhrPost({
        url: "ajaxUpdateUserProfile.php",
        form: 'userProfileForm',
        timeoutSeconds: 500000,
        load: function(response, ioArgs) {
            if(response == '1') {
                //Show Success Message
                dojo.byId('userProfileFormStatus').style.display = "";
                document.getElementById("userProfileFormStatus").setAttribute("class", "userProfileFormProcessingRequestMessage");
                document.getElementById("userProfileFormStatus").setAttribute("className", "userProfileFormProcessingRequestMessage");
                var currentTime = getCurrentTime();
                dojo.byId("userProfileFormStatusMessage").innerHTML = "Last Saved On: " + getCurrentTimeLongFormat(currentTime) +"";
                updateUserInformationLeftArea(currentTime);
                dijit.byId("resetUserProfileForm").attr("disabled", false);
                dijit.byId("submitUserProfileForm").attr("disabled", false);
                dijit.byId("submitUserProfileForm2").attr("disabled", false);

                /******/

                if (updateType == 0) {
                    dojo.byId("currentProfileSubmittedIndicator").value = dojo.byId("profileSubmittedIndicator").value;

                    dijit.byId("resetUpdateUserProfileForm0").attr("disabled", false);
                    dijit.byId("submitUpdateUserProfileForm0").attr("disabled", false);
                } else if (updateType == 1) {
                    dojo.byId("currentProfileSubmittedIndicator").value = dojo.byId("profileSubmittedIndicator").value;
                    dijit.byId("tempProfileSubmittedIndicator").attr("checked", false);

                    dijit.byId("verifyInvalidFieldsButton").attr("disabled", false);
                    dijit.byId("cancelUpdateUserProfileForm1").attr("disabled", false);
                    dijit.byId("submitUpdateUserProfileForm1").attr("disabled", false);
                } else if (updateType == 2) {
                    dojo.byId("currentProfileSubmittedIndicator").value = dojo.byId("profileSubmittedIndicator").value;
                    dijit.byId("tempProfileSubmittedIndicator").attr("checked", false);

                    dijit.byId("verifyInvalidFieldsButton2").attr("disabled", false);
                    dijit.byId("resetUpdateUserProfileForm2").attr("disabled", false);
                    dijit.byId("submitUpdateUserProfileForm2").attr("disabled", false);
                }

                dojo.byId("updateUserProfileValidSubmissionFormArea").style.display = "none";
                dojo.byId("updateUserProfileInvalidSubmissionFormArea").style.display = "none";
                dojo.byId("updateUserProfileInvalidSubmissionRemovalFormArea").style.display = "none";
                dojo.byId("updateUserProfileConfirmationArea").style.display = "";

                if (dojo.byId("currentProfileSubmittedIndicator").value == "0") {
                    dojo.byId("userProfileNotPublishedAttentionMessageArea").style.display = "";
                    dojo.byId("userProfilePublishedAttentionMessageArea").style.display = "none";
                } else {
                    dojo.byId("userProfileNotPublishedAttentionMessageArea").style.display = "none";
                    dojo.byId("userProfilePublishedAttentionMessageArea").style.display = "";
                }

                removeHighlightUserProfileInvalidFields();
            } else {
                //Show Error Message
                dojo.byId('userProfileFormStatus').style.display = "";
                document.getElementById("userProfileFormStatus").setAttribute("class", "userProfileFormErrorMessage");
                document.getElementById("userProfileFormStatus").setAttribute("className", "userProfileFormErrorMessage");
                dojo.byId("userProfileFormStatusMessage").innerHTML = "Invalid Parameter(s)!";
                dijit.byId("resetUserProfileForm").attr("disabled", false);
                dijit.byId("submitUserProfileForm").attr("disabled", false);
                dijit.byId("submitUserProfileForm2").attr("disabled", false);
            }
            return response;
        },
        error: function(response, ioArgs) {
            alert("ERROR!!!!");
            return response;
        }
    });

}

function getUserServicesProvidedString () {
    var parameters = "";
    var i = 0;
    var specialtyAreaList = consultantServicesProvidedStore._arrayOfAllItems;
    if(specialtyAreaList.length) {
        dojo.forEach(specialtyAreaList, function(selectedItem) {
            if(selectedItem !== null) {
                dojo.forEach(consultantServicesProvidedGrid.store.getAttributes(selectedItem), function(attribute) {
                    var value = consultantServicesProvidedGrid.store.getValues(selectedItem, attribute);
                    if (attribute == "id") {
                        parameters = parameters + value;
                    } else if (attribute == "servingSince") {
                        parameters = parameters + '-'+value+'&';
                        i++;
                    }
                });
            }
        });
    }

    return parameters;
}

function updateProfileSubmittedIndicator () {
    dojo.byId("profileSubmittedIndicator").value = (dijit.byId("tempProfileSubmittedIndicator").attr("checked")) ? 1 : 0;
}

function cancelUpdateUserProfileInvalidSubmission () {
    dojo.byId("updateUserProfileValidSubmissionFormArea").style.display = "none";
    dojo.byId("updateUserProfileInvalidSubmissionFormArea").style.display = "none";
    dojo.byId("updateUserProfileInvalidSubmissionRemovalFormArea").style.display = "none";
    dojo.byId("updateUserProfileConfirmationArea").style.display = "none";

    document.body.style.overflow = "";
    dijit.byId("updateUserProfileDialog").hide();
}

function cancelUpdateUserProfileValidSubmission () {
    dojo.byId("updateUserProfileValidSubmissionFormArea").style.display = "none";
    dojo.byId("updateUserProfileInvalidSubmissionFormArea").style.display = "none";
    dojo.byId("updateUserProfileInvalidSubmissionRemovalFormArea").style.display = "none";
    dojo.byId("updateUserProfileConfirmationArea").style.display = "none";
    /*
    if (dojo.byId("currentProfileSubmittedIndicator").value == 1) {
        dijit.byId("tempProfileSubmittedIndicator").attr("checked", true);
        dojo.byId("profileSubmittedIndicator").value = 1;
    } else {
        dijit.byId("tempProfileSubmittedIndicator").attr("checked", false);
        dojo.byId("profileSubmittedIndicator").value = 0;
    }
    */
    document.body.style.overflow = "";
    dijit.byId("updateUserProfileDialog").hide();
}

function cancelUpdateUserProfileValidSubmissionRemoval () {
    dojo.byId("updateUserProfileValidSubmissionFormArea").style.display = "none";
    dojo.byId("updateUserProfileInvalidSubmissionFormArea").style.display = "none";
    dojo.byId("updateUserProfileInvalidSubmissionRemovalFormArea").style.display = "none";
    dojo.byId("updateUserProfileConfirmationArea").style.display = "none";

    document.body.style.overflow = "";
    dijit.byId("updateUserProfileDialog").hide();
}

function closeUpdateUserProfileDialog () {
    document.body.style.overflow = "";
    dijit.byId("updateUserProfileDialog").hide();

    document.getElementById("updateUserProfileFormStatusMessage0").setAttribute("class", "");
    document.getElementById("updateUserProfileFormStatusMessage0").setAttribute("className", "");
    dojo.byId("updateUserProfileFormStatusMessage0").innerHTML = "";
    document.getElementById("updateUserProfileFormStatusMessage1").setAttribute("class", "");
    document.getElementById("updateUserProfileFormStatusMessage1").setAttribute("className", "");
    dojo.byId("updateUserProfileFormStatusMessage1").innerHTML = "";
    document.getElementById("updateUserProfileFormStatusMessage2").setAttribute("class", "");
    document.getElementById("updateUserProfileFormStatusMessage2").setAttribute("className", "");
    dojo.byId("updateUserProfileFormStatusMessage2").innerHTML = "";
}

function updateUserInformationLeftArea (currentTime) {

    var fadeOut = dojo.fadeOut({
        node: "userInformationLeftBarArea",
        duration: 1000
    });

    var updateInformation = function () {
        updateUserAccountProgress();
        dojo.byId("lastSaveProfileLeftAreaMessage").innerHTML = getCurrentTimeShortFormat(currentTime);
        
        /*
        if ((dojo.byId("profileSubmittedIndicator").value != 1) && (dojo.byId("currentProfileSubmittedIndicator").value != 1)) {
            dojo.byId("lastSubmitProfileLeftAreaMessage").innerHTML = getCurrentTimeShortFormat(currentTime);
            dojo.byId("dateOfRemovalLeftAreaMessage").innerHTML = getCurrentTimeShortFormat(new Date(currentTime.getTime() + (2 * 365 * 24 * 60 * 60 * 1000)));
            dojo.byId("currentProfileSubmittedIndicator").value = 1;
        } else {
            dojo.byId("currentProfileSubmittedIndicator").value = 0;
        }
        */

        if (dojo.byId("profileSubmittedIndicator").value == 1) {
            dojo.byId("isProfileAvailableQuesiton").innerHTML = 'Profile is currently available on the public registry? <span style="color:green;font-weight:bold;">YES</span>';
            dojo.byId("lastSubmitProfileLeftAreaMessage").innerHTML = getCurrentTimeShortFormat(currentTime);
            dojo.byId("dateOfRemovalLeftAreaMessage").innerHTML = getCurrentTimeShortFormat(new Date(currentTime.getTime() + (2 * 365 * 24 * 60 * 60 * 1000)));
        } else {
            dojo.byId("lastSubmitProfileLeftAreaMessage").innerHTML = "Not Available";
            dojo.byId("dateOfRemovalLeftAreaMessage").innerHTML = "Not Available";
            dojo.byId("isProfileAvailableQuesiton").innerHTML = 'Profile is currently available on the public registry? <span style="color:red;font-weight:bold;">NO</span>';
        }

    };
    dojo.connect(fadeOut, "onEnd", updateInformation);

    var fadeIn = dojo.fadeIn({
        node: "userInformationLeftBarArea",
        duration: 2000
    });

    dojo.fx.chain([fadeOut, fadeIn]).play();

}

function updateUserAccountProgress () {
    var createAccountComplete = 29.5;
    var requiredFiledComplete = 3.5;
    var otherFieldComplete = 3;

    var progress = 0 + createAccountComplete;

    if (dijit.byId("website").attr("value").length > 0) {
        progress += otherFieldComplete;
    }
    if (dijit.byId("email").attr("value").length > 0) {
        progress += requiredFiledComplete;
    }
    if (dijit.byId("cellphone").attr("value").length > 0) {
        progress += otherFieldComplete;
    }
    if (dijit.byId("telephone").attr("value").length > 0) {
        progress += requiredFiledComplete;
    }
    if (dijit.byId("mailingZipCode").attr("value") > 0) {
        progress += requiredFiledComplete;
    }
    if (dijit.byId("mailingStateId").attr("value") > 0) {
        progress += requiredFiledComplete;
    }
    if (dijit.byId("mailingCity").attr("value").length > 0) {
        progress += requiredFiledComplete;
    }
    if (dijit.byId("mailingAddress").attr("value").length > 0) {
        progress += requiredFiledComplete;
    }
    if (dijit.byId("physicalZipCode").attr("value") > 0) {
        progress += otherFieldComplete;
    }
    if (dijit.byId("physicalStateId").attr("value") > 0) {
        progress += otherFieldComplete;
    }
    if (dijit.byId("physicalCity").attr("value").length > 0) {
        progress += otherFieldComplete;
    }
    if (dijit.byId("physicalAddress").attr("value").length > 0) {
        progress += otherFieldComplete;
    }
    if (dijit.byId("companyName").attr("value").length > 0) {
        progress += requiredFiledComplete;
    }
    if (dijit.byId("lastName").attr("value").length > 0) {
        progress += requiredFiledComplete;
    }
    if (dijit.byId("firstName").attr("value").length > 0) {
        progress += requiredFiledComplete;
    }
    if (isServiceProvidedListValid()) {
        progress += requiredFiledComplete;
    }
    if ((dijit.byId("k12ClienteleIndicator").attr("value") == "1") || (dijit.byId("higherEducationClienteleIndicator").attr("value") == "1")) {
        progress += requiredFiledComplete;
    }
    if (dojo.byId("backgroundDescription").value.length > 0) {
        progress += requiredFiledComplete;
    }
    if (dojo.byId("educationDescription").value.length > 0) {
        progress += requiredFiledComplete;
    }
    if (dojo.byId("experienceDescription").value.length > 0) {
        progress += requiredFiledComplete;
    }
    if ((dijit.byId("complaintIndicator").attr("value") == "1") || (dijit.byId("pendingLitigationIndicator").attr("value") == "1") || (dijit.byId("noneIndicator").attr("value") == "1")) {
        progress += requiredFiledComplete;
    }
    
    dijit.byId("userAccountProgress").update({ 
        progress:progress
    });

    return progress;
    
}

function getCurrentTime () {
    return new Date();
}

function getCurrentTimeShortFormat (currentTime) {
    var time = "";

    var hours = currentTime.getHours();

    var meridiem = "AM";
    if(hours > 11){
        meridiem = "PM";
    }

    if (hours >= 12) {
        hours = hours - 12;
    }
    if (hours == 0) {
        hours = 12;
    }

    var minutes = currentTime.getMinutes();
    if (minutes < 10) {
        minutes = "0" + minutes;
    }

    var year = currentTime.getYear();
    if(year < 1000) {
        year += 1900;
    }

    var day = currentTime.getDate();
    if (day < 10) {
        day = "0" + day;
    }

    time = (currentTime.getMonth()+1) + "/" + day + "/" + year + " at " + hours + ":" + minutes + " " + meridiem;

    return time;
}

function getCurrentTimeLongFormat (currentTime) {
    var time = "";
    var hours = currentTime.getHours();
    var minutes = currentTime.getMinutes();

    if (minutes < 10) {
        minutes = "0" + minutes;
    }

    var meridiem = "AM";
    if(hours > 11){
        meridiem = "PM";
    }

    if (hours >= 12) {
        hours = hours - 12;
    }
    if (hours == 0) {
        hours = 12;
    }

    time = getDateStrWithDOW(currentTime) + " at " + hours + ":" + minutes + " " + meridiem;

    return time;
}

function getDateStrWithDOW (today) {
    var year = today.getYear();
    if(year < 1000) {
        year += 1900;
    }

    var day = today.getDate();
    if (day < 10) {
        day = "0" + day;
    }

    var todayStr = GetDay(today.getDay()) + ", ";
    todayStr += GetMonth(today.getMonth()) + " " + day;
    todayStr += ", " + year;
    return todayStr
}

function GetDay (intDay) {
    var DayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
        "Thursday", "Friday", "Saturday")
    return DayArray[intDay]
}

function GetMonth (intMonth) {
    var MonthArray = new Array("January", "February", "March",
        "April", "May", "June",
        "July", "August", "September",
        "October", "November", "December")
    return MonthArray[intMonth]
}

function isUserProfileFormValid () {
    var isUserProfileFormValid = true;

    if (!dijit.byId("firstName").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("lastName").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("companyName").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("physicalAddress").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("physicalCity").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("physicalStateId").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("physicalZipCode").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("mailingAddress").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("mailingCity").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("mailingStateId").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("mailingZipCode").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("telephone").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("telephoneExt").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("cellphone").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("email").isValid()) {
        isUserProfileFormValid = false;
    }
    if (!dijit.byId("website").isValid()) {
        isUserProfileFormValid = false;
    }
    /*
    if (!isServiceProvidedListValid()) {
        document.getElementById("serviceProvidedListErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("serviceProvidedListErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("serviceProvidedListErrorMessage").innerHTML = "Add at least one service provided";
        isUserProfileFormValid = false;
    } else {
        document.getElementById("serviceProvidedListErrorMessage").setAttribute("class", "");
        document.getElementById("serviceProvidedListErrorMessage").setAttribute("className", "");
        dojo.byId("serviceProvidedListErrorMessage").innerHTML = "";
    }
    */
    /*
    if ((dijit.byId("k12ClienteleIndicator").attr("value") == "") && (dijit.byId("higherEducationClienteleIndicator").attr("value") == "")) {
        document.getElementById("clienteleIndicatorErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("clienteleIndicatorErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("clienteleIndicatorErrorMessage").innerHTML = "Select at least one option";
        isUserProfileFormValid = false;
    } else {
        document.getElementById("clienteleIndicatorErrorMessage").setAttribute("class", "");
        document.getElementById("clienteleIndicatorErrorMessage").setAttribute("className", "");
        dojo.byId("clienteleIndicatorErrorMessage").innerHTML = "";
    }
    */
    /*
    if (dojo.byId("backgroundDescription").value.length == 0) {
        document.getElementById("backgroundDescriptionErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("backgroundDescriptionErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("backgroundDescriptionErrorMessage").innerHTML = "This is a required field";
        isUserProfileFormValid = false;
    } else {
        document.getElementById("backgroundDescriptionErrorMessage").setAttribute("class", "");
        document.getElementById("backgroundDescriptionErrorMessage").setAttribute("className", "");
        dojo.byId("backgroundDescriptionErrorMessage").innerHTML = "";
    }
    */
    /*
    if (dojo.byId("educationDescription").value.length == 0) {
        document.getElementById("educationDescriptionErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("educationDescriptionErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("educationDescriptionErrorMessage").innerHTML = "This is a required field";
        isUserProfileFormValid = false;
    } else {
        document.getElementById("educationDescriptionErrorMessage").setAttribute("class", "");
        document.getElementById("educationDescriptionErrorMessage").setAttribute("className", "");
        dojo.byId("educationDescriptionErrorMessage").innerHTML = "";
    }
    */
    /*
    if (dojo.byId("experienceDescription").value.length == 0) {
        document.getElementById("experienceDescriptionErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("experienceDescriptionErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("experienceDescriptionErrorMessage").innerHTML = "This is a required field";
        isUserProfileFormValid = false;
    } else {
        document.getElementById("experienceDescriptionErrorMessage").setAttribute("class", "");
        document.getElementById("experienceDescriptionErrorMessage").setAttribute("className", "");
        dojo.byId("experienceDescriptionErrorMessage").innerHTML = "";
    }
    */
    /*
    if ((dijit.byId("complaintIndicator").attr("value") == "") && (dijit.byId("pendingLitigationIndicator").attr("value") == "")) {
        document.getElementById("complaintPendingLitigationIndicatorErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("complaintPendingLitigationIndicatorErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("complaintPendingLitigationIndicatorErrorMessage").innerHTML = "Select at least one option";
        isUserProfileFormValid = false;
    } else {
        document.getElementById("complaintPendingLitigationIndicatorErrorMessage").setAttribute("class", "");
        document.getElementById("complaintPendingLitigationIndicatorErrorMessage").setAttribute("className", "");
        dojo.byId("complaintPendingLitigationIndicatorErrorMessage").innerHTML = "";
    }
    */

    if (!isUserProfileFormValid) {
        dijit.byId("website").focus();
        dijit.byId("email").focus();
        dijit.byId("cellphone").focus();
        dijit.byId("telephone").focus();
        dijit.byId("telephoneExt").focus();
        dijit.byId("mailingZipCode").focus();
        dijit.byId("mailingStateId").focus();
        dijit.byId("mailingCity").focus();
        dijit.byId("mailingAddress").focus();
        dijit.byId("physicalZipCode").focus();
        dijit.byId("physicalStateId").focus();
        dijit.byId("physicalCity").focus();
        dijit.byId("physicalAddress").focus();
        dijit.byId("companyName").focus();
        dijit.byId("lastName").focus();
        dijit.byId("firstName").focus();

        document.body.scrollTop = 200;
        manageUserProfileFormStatus();
    }

    return isUserProfileFormValid;
}

function highlightUserProfileInvalidFields () {
    document.body.style.overflow = "";
    dijit.byId("updateUserProfileDialog").hide();
    /*
    if (!isServiceProvidedListValid()) {
        document.getElementById("serviceProvidedListErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("serviceProvidedListErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("serviceProvidedListErrorMessage").innerHTML = "Add at least one service provided";
    } else {
        document.getElementById("serviceProvidedListErrorMessage").setAttribute("class", "");
        document.getElementById("serviceProvidedListErrorMessage").setAttribute("className", "");
        dojo.byId("serviceProvidedListErrorMessage").innerHTML = "";
    }
    if (!dijit.byId("k12ClienteleIndicator").attr("checked") && !dijit.byId("higherEducationClienteleIndicator").attr("checked")) {
        document.getElementById("clienteleIndicatorErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("clienteleIndicatorErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("clienteleIndicatorErrorMessage").innerHTML = "Select at least one option";
    } else {
        document.getElementById("clienteleIndicatorErrorMessage").setAttribute("class", "");
        document.getElementById("clienteleIndicatorErrorMessage").setAttribute("className", "");
        dojo.byId("clienteleIndicatorErrorMessage").innerHTML = "";
    }
    if (dojo.byId("backgroundDescription").value.length == 0) {
        document.getElementById("backgroundDescriptionErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("backgroundDescriptionErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("backgroundDescriptionErrorMessage").innerHTML = "This is a required field";
    } else {
        document.getElementById("backgroundDescriptionErrorMessage").setAttribute("class", "");
        document.getElementById("backgroundDescriptionErrorMessage").setAttribute("className", "");
        dojo.byId("backgroundDescriptionErrorMessage").innerHTML = "";
    }
    if (dojo.byId("educationDescription").value.length == 0) {
        document.getElementById("educationDescriptionErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("educationDescriptionErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("educationDescriptionErrorMessage").innerHTML = "This is a required field";
    } else {
        document.getElementById("educationDescriptionErrorMessage").setAttribute("class", "");
        document.getElementById("educationDescriptionErrorMessage").setAttribute("className", "");
        dojo.byId("educationDescriptionErrorMessage").innerHTML = "";
    }
    if (dojo.byId("experienceDescription").value.length == 0) {
        document.getElementById("experienceDescriptionErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("experienceDescriptionErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("experienceDescriptionErrorMessage").innerHTML = "This is a required field";
    } else {
        document.getElementById("experienceDescriptionErrorMessage").setAttribute("class", "");
        document.getElementById("experienceDescriptionErrorMessage").setAttribute("className", "");
        dojo.byId("experienceDescriptionErrorMessage").innerHTML = "";
    }
    if (!dijit.byId("complaintIndicator").attr("checked") && !dijit.byId("pendingLitigationIndicator").attr("checked") && !dijit.byId("noneIndicator").attr("checked")) {
        document.getElementById("complaintPendingLitigationIndicatorErrorMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("complaintPendingLitigationIndicatorErrorMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("complaintPendingLitigationIndicatorErrorMessage").innerHTML = "Select at least one option";
    } else {
        document.getElementById("complaintPendingLitigationIndicatorErrorMessage").setAttribute("class", "");
        document.getElementById("complaintPendingLitigationIndicatorErrorMessage").setAttribute("className", "");
        dojo.byId("complaintPendingLitigationIndicatorErrorMessage").innerHTML = "";
    }
    */
    var isBasicInformationComplete = true;
    if (dijit.byId("firstName").attr("value").length == 0) {
        isBasicInformationComplete = false;
        dojo.byId("firstNameLabel").style.color = "red";
    } else {
        dojo.byId("firstNameLabel").style.color = "";
    }
    if (dijit.byId("lastName").attr("value").length == 0) {
        isBasicInformationComplete = false;
        dojo.byId("lastNameLabel").style.color = "red";
    } else {
        dojo.byId("lastNameLabel").style.color = "";
    }
    if (dijit.byId("companyName").attr("value").length == 0) {
        isBasicInformationComplete = false;
        dojo.byId("companyNameLabel").style.color = "red";
    } else {
        dojo.byId("companyNameLabel").style.color = "";
    }
    if (!isBasicInformationComplete) {
        dojo.byId("basicInformationLabel").style.color = "red";
    } else {
        dojo.byId("basicInformationLabel").style.color = "";
    }


    var isMailingAddressComplete = true;
    if (dijit.byId("mailingAddress").attr("value").length == 0) {
        isMailingAddressComplete = false;
        dojo.byId("mailingStreetLabel").style.color = "red";
    } else {
        dojo.byId("mailingStreetLabel").style.color = "";
    }
    if (dijit.byId("mailingCity").attr("value").length == 0) {
        isMailingAddressComplete = false;
        dojo.byId("mailingCityLabel").style.color = "red";
    } else {
        dojo.byId("mailingCityLabel").style.color = "";
    }
    if (!(dijit.byId("mailingStateId").attr("value") > 0)) {
        isMailingAddressComplete = false;
        dojo.byId("mailingStateIdLabel").style.color = "red";
    } else {
        dojo.byId("mailingStateIdLabel").style.color = "";
    }
    if (!(dijit.byId("mailingZipCode").attr("value") > 0)) {
        isMailingAddressComplete = false;
        dojo.byId("mailingZipCodeLabel").style.color = "red";
    } else {
        dojo.byId("mailingZipCodeLabel").style.color = "";
    }
    if (!isMailingAddressComplete) {
        dojo.byId("mailingAddressLabel").style.color = "red";
    } else {
        dojo.byId("mailingAddressLabel").style.color = "";
    }

    var isContactInformationComplete = true;
    if (dijit.byId("telephone").attr("value").length == 0) {
        isContactInformationComplete = false;
        dojo.byId("telephoneLabel").style.color = "red";
    } else {
        dojo.byId("telephoneLabel").style.color = "";
    }
    if (dijit.byId("email").attr("value").length == 0) {
        isContactInformationComplete = false;
        dojo.byId("emailLabel").style.color = "red";
    } else {
        dojo.byId("emailLabel").style.color = "";
    }
    if (!isContactInformationComplete) {
        dojo.byId("contactInformationLabel").style.color = "red";
    } else {
        dojo.byId("contactInformationLabel").style.color = "";
    }


    if (!isServiceProvidedListValid()) {
        dojo.byId("servicesOfferedLabel").style.color = "red";
    } else {
        dojo.byId("servicesOfferedLabel").style.color = "";
    }
    if (!dijit.byId("k12ClienteleIndicator").attr("checked") && !dijit.byId("higherEducationClienteleIndicator").attr("checked")) {
        dojo.byId("clienteleLabel").style.color = "red";
    } else {
        dojo.byId("clienteleLabel").style.color = "";
    }
    if (dojo.byId("backgroundDescription").value.length == 0) {
        dojo.byId("backgroundLabel").style.color = "red";
    } else {
        dojo.byId("backgroundLabel").style.color = "";
    }
    if (dojo.byId("educationDescription").value.length == 0) {
        dojo.byId("educationLabel").style.color = "red";
    } else {
        dojo.byId("educationLabel").style.color = "";
    }
    if (dojo.byId("experienceDescription").value.length == 0) {
        dojo.byId("experienceLabel").style.color = "red";
    } else {
        dojo.byId("experienceLabel").style.color = "";
    }
    if (!dijit.byId("complaintIndicator").attr("checked") && !dijit.byId("pendingLitigationIndicator").attr("checked") && !dijit.byId("noneIndicator").attr("checked")) {
        dojo.byId("complaintPendingLitigationLabel").style.color = "red";
    } else {
        dojo.byId("complaintPendingLitigationLabel").style.color = "";
    }

    dojo.byId('userProfileFormStatus').style.display = "";
    document.getElementById("userProfileFormStatus").setAttribute("class", "userProfileFormErrorMessage");
    document.getElementById("userProfileFormStatus").setAttribute("className", "userProfileFormErrorMessage");
    dojo.byId("userProfileFormStatusMessage").innerHTML = "Please complete the required fields in <span style='color:red;'>RED</span>.";

}

function removeHighlightUserProfileInvalidFields () {

    dojo.byId("firstNameLabel").style.color = "";
    dojo.byId("lastNameLabel").style.color = "";
    dojo.byId("companyNameLabel").style.color = "";
    dojo.byId("basicInformationLabel").style.color = "";
    dojo.byId("mailingStreetLabel").style.color = "";
    dojo.byId("mailingCityLabel").style.color = "";
    dojo.byId("mailingStateIdLabel").style.color = "";
    dojo.byId("mailingZipCodeLabel").style.color = "";
    dojo.byId("mailingAddressLabel").style.color = "";
    dojo.byId("telephoneLabel").style.color = "";
    dojo.byId("emailLabel").style.color = "";
    dojo.byId("contactInformationLabel").style.color = "";
    dojo.byId("servicesOfferedLabel").style.color = "";
    dojo.byId("clienteleLabel").style.color = "";
    dojo.byId("backgroundLabel").style.color = "";
    dojo.byId("educationLabel").style.color = "";
    dojo.byId("experienceLabel").style.color = "";
    dojo.byId("complaintPendingLitigationLabel").style.color = "";

}

function isServiceProvidedListValid () {
    var isServiceProvidedListValid = true;

    var i = 0;
    var specialtyAreaList = consultantServicesProvidedStore._arrayOfAllItems;
    if(specialtyAreaList.length) {
        dojo.forEach(specialtyAreaList, function(selectedItem) {
            if(selectedItem !== null) {
                dojo.forEach(consultantServicesProvidedGrid.store.getAttributes(selectedItem), function(attribute) {
                    var value = consultantServicesProvidedGrid.store.getValues(selectedItem, attribute);
                    if (attribute == "id") {
                    //parameters = parameters + value;
                    } else if (attribute == "servingSince") {
                        //parameters = parameters + '-'+value+'&';
                        i++;
                    }
                });
            }
        });
    }

    if (i == 0) {
        isServiceProvidedListValid = false;
    }

    return isServiceProvidedListValid;
}

function submitUserAccountForm () {
    var tempFirstName = dijit.byId("firstName").attr("value");
    var tempLastName = dijit.byId("lastName").attr("value");

    dojo.byId('userAccountFormStatus').style.display = "";
    document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormProcessingRequestMessage");
    document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormProcessingRequestMessage");
    dojo.byId("userAccountFormStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0' style='margin-left:left;margin-right:left;'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:12px;font-weight:bold;'>Your request is being processed...</td></tr></table>";

    if (!isUserAccountFormValid()) {
        dojo.byId('userAccountFormStatus').style.display = "";
        document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormErrorMessage");
        document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormErrorMessage");
        dojo.byId("userAccountFormStatusMessage").innerHTML = "Invalid Parameter(s). Please verify the information provided.";
    } else {

        if (dijit.byId("changePasswordIndicator").attr("checked") == true) {
            if (dijit.byId("newPassword").attr("value") != dijit.byId("confirmationNewPassword").attr("value")) {
                dijit.byId("newPassword").attr("value" , "");
                dijit.byId("confirmationNewPassword").attr("value" , "");
                dojo.byId('userAccountFormStatus').style.display = "";
                document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormErrorMessage");
                document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormErrorMessage");
                dojo.byId("userAccountFormStatusMessage").innerHTML = "Invalid Password. They are different.";
                return false;
            }
        }
        
        dijit.byId("resetUserAccountForm").attr("disabled", true);
        dijit.byId("deleteUserAccount").attr("disabled", true);
        dijit.byId("submitUserAccountForm").attr("disabled", true);
        dojo.xhrPost({
            url: "ajaxUpdateUserAccount.php",
            form: 'userAccountForm',
            timeoutSeconds: 500000,
            load: function(response, ioArgs) {
                if(response == '1') {
                    //Show Success Message
                    dojo.byId('userAccountFormStatus').style.display = "";
                    document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormProcessingRequestMessage");
                    document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormProcessingRequestMessage");
                    var currentTime = new Date();
                    dojo.byId("userAccountFormStatusMessage").innerHTML = "Last Saved On: " + getCurrentTimeLongFormat(currentTime) +"";
                    dijit.byId("resetUserAccountForm").attr("disabled", false);
                    dijit.byId("deleteUserAccount").attr("disabled", false);
                    dijit.byId("submitUserAccountForm").attr("disabled", false);
                    //CHANGE USER NAME
                    updateUserInformation(tempFirstName, tempLastName);
                } else if (response == 'InvalidLoginException') {
                    dojo.byId('userAccountFormStatus').style.display = "";
                    document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormErrorMessage");
                    document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormErrorMessage");
                    dojo.byId("userAccountFormStatusMessage").innerHTML = "Invalid Old Password!";
                    dijit.byId("resetUserAccountForm").attr("disabled", false);
                    dijit.byId("deleteUserAccount").attr("disabled", false);
                    dijit.byId("submitUserAccountForm").attr("disabled", false);
                } else if (response == 'DuplicateEmailException') {
                    dojo.byId('userAccountFormStatus').style.display = "";
                    document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormErrorMessage");
                    document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormErrorMessage");
                    dojo.byId("userAccountFormStatusMessage").innerHTML = "Duplicate Email!";
                    dijit.byId("resetUserAccountForm").attr("disabled", false);
                    dijit.byId("deleteUserAccount").attr("disabled", false);
                    dijit.byId("submitUserAccountForm").attr("disabled", false);
                } else {
                    //Show Error Message
                    dojo.byId('userAccountFormStatus').style.display = "";
                    document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormErrorMessage");
                    document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormErrorMessage");
                    dojo.byId("userAccountFormStatusMessage").innerHTML = "Invalid Parameter(s)!";
                    dijit.byId("resetUserAccountForm").attr("disabled", false);
                    dijit.byId("deleteUserAccount").attr("disabled", false);
                    dijit.byId("submitUserAccountForm").attr("disabled", false);
                }
                return response;
            },
            error: function(response, ioArgs) {
                alert("ERROR!!!!");
                return response;
            }
        });
    }
    return true;
}

function isUserAccountFormValid () {
    var isUserAccountFormValid = true;

    if (!dijit.byId("firstName").isValid()) {
        isUserAccountFormValid = false;
    }
    if (!dijit.byId("lastName").isValid()) {
        isUserAccountFormValid = false;
    }
    if (dijit.byId("changePasswordIndicator").attr("checked") == true) {
        if (!dijit.byId("oldPassword").isValid()) {
            isUserAccountFormValid = false;
        }
        if (!dijit.byId("newPassword").isValid()) {
            isUserAccountFormValid = false;
        }
        if (!dijit.byId("confirmationNewPassword").isValid()) {
            isUserAccountFormValid = false;
        }
    }
    
    if (!isUserAccountFormValid) {
        dijit.byId("confirmationNewPassword").focus();
        dijit.byId("newPassword").focus();
        dijit.byId("oldPassword").focus();
        dijit.byId("lastName").focus();
        dijit.byId("firstName").focus();
    }

    return isUserAccountFormValid;
}

function updateUserInformation (firstName, lastName) {
    var fadeOut = dojo.fadeOut({
        node: "menu6",
        duration: 1000
    });
    var setNewLogoutAreaMessage = function () {
        dojo.byId("menu6").style.backgroundColor = "#FF6600";
        dojo.byId("userLogoutArea").innerHTML = '<span style="font-size:10px;">You are currently logged in as:</span><br />' + firstName + ' ' + lastName + '&nbsp;|&nbsp;&nbsp;<a href="index.php" class="topMenuLink">Logout</a>';
    };
    dojo.connect(fadeOut,"onEnd",setNewLogoutAreaMessage);

    var fadeIn = dojo.fadeIn({
        node: "menu6",
        duration: 1000
    });
    
    var setNewLogoutAreaColor = function () {
        setTimeout("changeColorAnimation()", 5000);
    };
    dojo.connect(fadeIn,"onEnd",setNewLogoutAreaColor);

    dojo.fx.chain([fadeOut, fadeIn]).play();
}

function changeColorAnimation () {
    var orangeToBlack = dojo.animateProperty({
        node: "menu6",
        duration: 1000,
        properties: {
            backgroundColor: {
                start:"#FF6600",
                end:"black"
            }
        }
    });
    orangeToBlack.play();
    
    var cleanColor = function () {
        dojo.byId("menu6").style.backgroundColor = "";
    };
    dojo.connect(orangeToBlack,"onEnd",cleanColor);
}

function deleteUserAccount () {
    
    var answer = confirm ("You are about to completely delete your account and profile within\nthe Safety & Security Consultant Registry of Texas.\n\nAre you sure?");
    if (answer) {
        dojo.byId('userAccountFormStatus').style.display = "";
        document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormProcessingRequestMessage");
        document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormProcessingRequestMessage");
        dojo.byId("userAccountFormStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0' style='margin-left:auto;margin-right:auto;'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:12px;font-weight:bold;'>Your request is being processed...</td></tr></table>";


        dijit.byId("resetUserAccountForm").attr("disabled", true);
        dijit.byId("deleteUserAccount").attr("disabled", true);
        dijit.byId("submitUserAccountForm").attr("disabled", true);
        dojo.xhrPost({
            url: "ajaxDeleteUserAccount.php",
            form: 'userAccountForm',
            timeoutSeconds: 500000,
            load: function(response, ioArgs) {
                if(response == '1') {
                    //Show Success Message
                    dojo.byId('userAccountFormStatus').style.display = "";
                    document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormProcessingRequestMessage");
                    document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormProcessingRequestMessage");
                    dojo.byId("userAccountFormStatusMessage").innerHTML = "Your Account has been deleted!!";
                    alert("Your Account has been deleted!!");
                    window.location = "index.php"
                } else {
                    //Show Error Message
                    dojo.byId('userAccountFormStatus').style.display = "";
                    document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormErrorMessage");
                    document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormErrorMessage");
                    dojo.byId("userAccountFormStatusMessage").innerHTML = "Account Deletion Failed!";
                    dijit.byId("resetUserAccountForm").attr("disabled", false);
                    dijit.byId("deleteUserAccount").attr("disabled", false);
                    dijit.byId("submitUserAccountForm").attr("disabled", false);
                }
                return response;
            },
            error: function(response, ioArgs) {
                alert("ERROR!!!!");
                return response;
            }
        });
    } else {

    }
    return true;
}

function activateChangeUserAccountPassword () {
    if (dijit.byId("changePasswordIndicator").attr("checked") == true) {
        dijit.byId("oldPassword").attr("disabled", false);
        dijit.byId("newPassword").attr("disabled", false);
        dijit.byId("confirmationNewPassword").attr("disabled", false);
        dojo.byId("oldPasswordRequiredMessage").innerHTML = '<span class="requiredSign">*</span>';
        dojo.byId("newPasswordRequiredMessage").innerHTML = '<span class="requiredSign">*</span>';
        dojo.byId("confirmationPasswordRequiredMessage").innerHTML = '<span class="requiredSign">*</span>';
    } else {
        dijit.byId("oldPassword").attr("disabled", true);
        dijit.byId("newPassword").attr("disabled", true);
        dijit.byId("confirmationNewPassword").attr("disabled", true);
        dijit.byId("oldPassword").reset();
        dijit.byId("newPassword").reset();
        dijit.byId("confirmationNewPassword").reset();
        dojo.byId("oldPasswordRequiredMessage").innerHTML = '';
        dojo.byId("newPasswordRequiredMessage").innerHTML = '';
        dojo.byId("confirmationPasswordRequiredMessage").innerHTML = '';
    }
}

function submitSearchConsultantForm () {
    
    dojo.byId("consultantSearchResultArea").style.display = "";
    dojo.byId("consultantSearchResultAreaStatusMessage").style.display = "none";

    dojo.fadeOut({
        node: "consultantSearchResultArea",
        duration: 1000
    }).play();

    //dojo.byId('userAccountFormStatus').style.display = "";
    document.getElementById("searchConsultantStatusMessage").setAttribute("class", "searchConsultantFormProcessingRequestMessage");
    document.getElementById("searchConsultantStatusMessage").setAttribute("className", "searchConsultantFormProcessingRequestMessage");
    dojo.byId("searchConsultantStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:12px;font-weight:bold;'>Searching...</td></tr></table>";


    dijit.byId("resetConsultantButton").attr("disabled", true);
    dijit.byId("searchConsultantButton").attr("disabled", true);
    dojo.xhrPost({
        url: "ajaxSearchConsultants.php",
        form: 'searchConsultantForm',
        timeoutSeconds: 500000,
        handleAs:"json",
        load: function(response, ioArgs) {
            if(true) {

                if (response.totalNumberResults == 0) {
                    dojo.byId("consultantSearchResultAreaStatusMessage").style.display = "";
                    dojo.byId("consultantSearchResultArea").style.display = "none";
                    dojo.byId("consultantSearchResultAreaStatusMessage").innerHTML = "0 Results Found.";


                    document.getElementById("searchConsultantStatusMessage").setAttribute("class", "searchConsultantFormProcessingRequestMessage");
                    document.getElementById("searchConsultantStatusMessage").setAttribute("className", "searchConsultantFormProcessingRequestMessage");
                    dojo.byId("searchConsultantStatusMessage").innerHTML = "Search Completed.";
                    dijit.byId("resetConsultantButton").attr("disabled", false);
                    dijit.byId("searchConsultantButton").attr("disabled", false);

                    return true;
                }

                //Show Success Message
                dojo.byId("searchResultPageIndicator").innerHTML = "Results <b>" + ((response.pageNumber * 20) + 1) + " - " + ((response.pageNumber * 20) + parseInt(response.totalNumberPageResults)) + "</b> of <b>" + response.totalNumberResults + "</b>"
                dojo.byId("searchResultPageIndicator").innerHTML = "Results <b>" + ((response.pageNumber * 20) + 1) + " - " + ((response.pageNumber * 20) + parseInt(response.totalNumberPageResults)) + "</b> of <b>" + response.totalNumberResults + "</b>"
                //var newConsultantStore = new dojo.data.ItemFileReadStore({data: response});
                //consultantAreaGrid.setStore(newConsultantStore);

                consultantsStore = new dojo.data.ItemFileReadStore({
                    data: response
                });
                consultantAreaGrid.setStore(consultantsStore);

                addFilterParametersToPaginationNavigationParameters();
                dojo.byId("paginationMenuArea").innerHTML = generatePaginationNavigationMenu(response.totalNumberResults, response.totalNumberPageResults, response.pageNumber);

                dojo.fadeIn({
                    node: "consultantSearchResultArea",
                    duration: 1000
                }).play();
                
                //dojo.byId('userAccountFormStatus').style.display = "";
                document.getElementById("searchConsultantStatusMessage").setAttribute("class", "searchConsultantFormProcessingRequestMessage");
                document.getElementById("searchConsultantStatusMessage").setAttribute("className", "searchConsultantFormProcessingRequestMessage");
                dojo.byId("searchConsultantStatusMessage").innerHTML = "Search Completed.";
                dijit.byId("resetConsultantButton").attr("disabled", false);
                dijit.byId("searchConsultantButton").attr("disabled", false);
            } else {
                //Show Error Message
                //dojo.byId('userAccountFormStatus').style.display = "";
                //document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormErrorMessage");
                //document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormErrorMessage");
                //dojo.byId("userAccountFormStatus").innerHTML = "Account Deletion Failed!";
                dijit.byId("resetConsultantButton").attr("disabled", false);
                dijit.byId("searchConsultantButton").attr("disabled", false);
            }
            return response;
        },
        error: function(response, ioArgs) {
            alert("ERROR!!!!");
            return response;
        }
    });
    return true;
}

function resetSearchConsultantForm () {
    dijit.byId("k12Indicator").reset();
    dijit.byId("higherEducationIndicator").reset();
    dijit.byId("consultantName").reset();
    dijit.byId("email").reset();
    dijit.byId("companyName").reset();
    clearSelectedServicesToFilter();
    deactivateSearchConsultantFilterForm();
}

function activateSearchConsultantFilterForm () {
    dijit.byId("consultantName").attr("disabled", false);
    dijit.byId("email").attr("disabled", false);
    dijit.byId("companyName").attr("disabled", false);
    dijit.byId("selectServicesDialog").attr("disabled", false);

    dojo.byId("selectedServicesListArea").style.backgroundColor = "#FFFFFF";

    dijit.byId("resetConsultantButton").attr("disabled", false);
    dijit.byId("searchConsultantButton").attr("disabled", false);

}

function deactivateSearchConsultantFilterForm () {
    dijit.byId("consultantName").attr("disabled", true);
    dijit.byId("email").attr("disabled", true);
    dijit.byId("companyName").attr("disabled", true);
    dijit.byId("selectServicesDialog").attr("disabled", true);

    dojo.byId("selectedServicesListArea").style.backgroundColor = "#EEEEEE";

    dijit.byId("resetConsultantButton").attr("disabled", true);
    dijit.byId("searchConsultantButton").attr("disabled", true);
}

function addSelectedServicesToFilter () {
    dojo.byId("selectedServicesListArea").innerHTML = "";
    var servicesSelectedCount = dojo.byId("servicesSelectedCount").value;
    for (i = 0; i < servicesSelectedCount; i++) {
        dojo.byId("service"+i).value = "false";
    }
    var rowNumber = 0;
    for (i = 0; i < servicesSelectedCount; i++) {
        if (dijit.byId("tempService"+i).attr("checked")) {
            if ((rowNumber % 2) != 0) {
                dojo.byId("selectedServicesListArea").innerHTML += '<div style="background-color:#EEEEEE;padding:5px 5px 5px 5px;">' + dojo.byId("serviceName"+i).innerHTML + '</div>';
            } else {
                dojo.byId("selectedServicesListArea").innerHTML += '<div style="padding:5px 5px 5px 5px;">' + dojo.byId("serviceName"+i).innerHTML + '</div>';
            }
            dojo.byId("service"+i).value = dijit.byId("tempService"+i).attr("value");
            rowNumber++;
        }
    }
    dijit.byId("searchConsultantButton").focus();
}

function clearSelectedServicesToFilter () {
    dojo.byId("selectedServicesListArea").innerHTML = "";
    var servicesSelectedCount = dojo.byId("servicesSelectedCount").value
    for (i = 0; i < servicesSelectedCount; i++) {
        dijit.byId("tempService"+i).reset();
        dojo.byId("service"+i).value = "false";
    }
}

function showConsultantInformationDetail (e) {
    //alert("ROW INDEX :: " + e.rowIndex);
    //alert(consultantAreaGrid.get(e.rowIndex, consultantsStore));
    //alert(consultantAreaGrid.getItemIndex(consultantAreaGrid.getItem(e.rowIndex)));

    //alert(consultantAreaGrid.getItem(e.rowIndex).email);
    //cell
    //grid

    var consultantEmail = consultantAreaGrid.getItem(e.rowIndex).accountEmail;
    showConsultantDetailInformationDialog();

    dojo.xhrPost({
        url: "ajaxConsultantDetailInformationInclude.php?accountEmail="+consultantEmail,
        timeoutSeconds: 500000,
        handleAs:"text",
        load: function(response, ioArgs) {
            if(response != "") {
                //Show Success Message
                dojo.byId("consultantDetailInformationDialogArea").innerHTML = response;
            } else {
            //Show Error Message
                
            }
            return response;
        },
        error: function(response, ioArgs) {
            alert("ERROR!!!!");
            return response;
        }
    });
    
}

function showConsultantDetailInformationDialog () {
    document.body.style.overflow = "hidden";
    dijit.byId('consultantDetailInformationDialog').show();
    dojo.byId("consultantDetailInformationDialogArea").innerHTML = "";
}

function hideConsultantDetailInformationDialog () {
    document.body.style.overflow = "";
    dijit.byId('consultantDetailInformationDialog').hide();
    dojo.byId("consultantDetailInformationDialogArea").innerHTML = "";
}

function printConsultantInformation (consultantEmail) {
    alert("Work in Progress...");
}

function addFilterParametersToPaginationNavigationParameters () {
    var servicesSelectedCount = dojo.byId("paginationServicesSelectedCount").value;
    for (i = 0; i < servicesSelectedCount; i++) {
        dojo.byId("paginationService"+i).value = "false";
    }
    var rowNumber = 0;
    for (i = 0; i < servicesSelectedCount; i++) {
        if (dijit.byId("tempService"+i).attr("checked")) {
            dojo.byId("paginationService"+i).value = dijit.byId("tempService"+i).attr("value");
            rowNumber++;
        }
    }

    
    if (dijit.byId("k12Indicator").attr("checked")) {
        dojo.byId("paginationSearchIndicator").value = 0;
    } else {
        dojo.byId("paginationSearchIndicator").value = 1;
    }
    
    dojo.byId("paginationConsultantName").value = dijit.byId("consultantName").attr("value");
    dojo.byId("paginationEmail").value = dijit.byId("email").attr("value");
    dojo.byId("paginationCompanyName").value = dijit.byId("companyName").attr("value");
    

}

function generatePaginationNavigationMenu(totalNumberResults, totalNumberPageResults, pageNumber) {

    var currentPageNumber = parseInt(pageNumber) + 1;

    var totalNumberPages = Math.round((totalNumberResults / 20));
    //alert(totalNumberPages);
    /*
    if ((5 > (totalNumberResults % 20)) && (0 < (totalNumberResults % 10))) {
        totalNumberPages++;
    }
    */
    //alert(totalNumberResults);
    /*
    if ((totalNumberResults % 20) > 0 && ((totalNumberResults / 20) > 0)) {
        totalNumberPages++;
    }
    */

    if (((totalNumberResults / 20) > totalNumberPages)) {
        totalNumberPages++;
    }

    //alert(totalNumberPages);
    var navigationMenu = '<table id="pagination-digg"><tbody><tr>';

    if (pageNumber == 0) {
        navigationMenu += '<td id="paginationFirst" class="previous-off">« First</td>';
        navigationMenu += '<td id="paginationPrevious" class="previous-off">« Previous</td>';
    } else {
        navigationMenu += '<td id="paginationFirst" class="previous"><a href="#" onclick="javascript:searchConsultantGoToPage(0);">« First</a></td>';
        navigationMenu += '<td id="paginationPrevious" class="previous"><a href="#" onclick="javascript:searchConsultantGoToPage(' + (parseInt(pageNumber) - 1) + ');">« Previous</a></td>';
    }
    
    var startPagination = 1;
    if (currentPageNumber > 7) {
        startPagination  = startPagination + (currentPageNumber - 7);
    }
    var j = 1;
    //alert(startPagination);
    //alert(totalNumberPages);
    for (var i = startPagination; i <= totalNumberPages && j <= 7; i++) {
        j++;
        if (currentPageNumber == i) {
            navigationMenu += '<td id="paginationPage' + i + '" class="active">' + i + '</td>';
        } else {
            navigationMenu += '<td id="paginationPage' + i + '"><a href="#" onclick="javascript:searchConsultantGoToPage(' + (i - 1) + ');">' + i + '</a></td>';
        }
    }

    if (currentPageNumber == totalNumberPages) {
        navigationMenu += '<td id="paginationNext" class="next-off">Next »</td>';
        navigationMenu += '<td id="paginationLast" class="next-off">Last »</td>';
    } else {
        navigationMenu += '<td class="next" id="paginationNext"><a href="#" onclick="javascript:searchConsultantGoToPage(' + (parseInt(pageNumber) + 1) + ');">Next »</a></td>';
        navigationMenu += '<td class="next" id="paginationLast"><a href="#" onclick="javascript:searchConsultantGoToPage(' + (totalNumberPages - 1) + ');">Last »</a></td>';
    }

    navigationMenu += '</tr></tbody></table>';

    return navigationMenu;
}

function searchConsultantGoToPage (pageNumber) {

    dojo.byId("consultantSearchResultArea").style.display = "";
    dojo.byId("consultantSearchResultAreaStatusMessage").style.display = "none";

    dojo.fadeOut({
        node: "consultantSearchResultArea",
        duration: 1000
    }).play();

    //dojo.byId('userAccountFormStatus').style.display = "";
    document.getElementById("searchConsultantStatusMessage").setAttribute("class", "searchConsultantFormProcessingRequestMessage");
    document.getElementById("searchConsultantStatusMessage").setAttribute("className", "searchConsultantFormProcessingRequestMessage");
    dojo.byId("searchConsultantStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:12px;font-weight:bold;'>Searching...</td></tr></table>";


    dijit.byId("resetConsultantButton").attr("disabled", true);
    dijit.byId("searchConsultantButton").attr("disabled", true);

    dojo.byId("paginationGoToPage").value = pageNumber;

    dojo.xhrPost({
        url: "ajaxSearchConsultants.php",
        form: 'pagination',
        timeoutSeconds: 500000,
        handleAs:"json",
        load: function(response, ioArgs) {
            if(true) {
                //Show Success Message
                dojo.byId("searchResultPageIndicator").innerHTML = "Results <b>" + ((response.pageNumber * 20) + 1) + " - " + ((response.pageNumber * 20) + parseInt(response.totalNumberPageResults)) + "</b> of <b>" + response.totalNumberResults + "</b>"
                dojo.byId("searchResultPageIndicator").innerHTML = "Results <b>" + ((response.pageNumber * 20) + 1) + " - " + ((response.pageNumber * 20) + parseInt(response.totalNumberPageResults)) + "</b> of <b>" + response.totalNumberResults + "</b>"
                //var newConsultantStore = new dojo.data.ItemFileReadStore({data: response});
                //consultantAreaGrid.setStore(newConsultantStore);

                consultantsStore = new dojo.data.ItemFileReadStore({
                    data: response
                });
                consultantAreaGrid.setStore(consultantsStore);

                dojo.byId("paginationMenuArea").innerHTML = generatePaginationNavigationMenu(response.totalNumberResults, response.totalNumberPageResults, response.pageNumber);

                dojo.fadeIn({
                    node: "consultantSearchResultArea",
                    duration: 1000
                }).play();

                //dojo.byId('userAccountFormStatus').style.display = "";
                document.getElementById("searchConsultantStatusMessage").setAttribute("class", "searchConsultantFormProcessingRequestMessage");
                document.getElementById("searchConsultantStatusMessage").setAttribute("className", "searchConsultantFormProcessingRequestMessage");
                dojo.byId("searchConsultantStatusMessage").innerHTML = "Search Completed.";
                dijit.byId("resetConsultantButton").attr("disabled", false);
                dijit.byId("searchConsultantButton").attr("disabled", false);
            } else {
                //Show Error Message
                //dojo.byId('userAccountFormStatus').style.display = "";
                //document.getElementById("userAccountFormStatus").setAttribute("class", "userProfileFormErrorMessage");
                //document.getElementById("userAccountFormStatus").setAttribute("className", "userProfileFormErrorMessage");
                //dojo.byId("userAccountFormStatus").innerHTML = "Account Deletion Failed!";
                dijit.byId("resetConsultantButton").attr("disabled", false);
                dijit.byId("searchConsultantButton").attr("disabled", false);
            }
            return response;
        },
        error: function(response, ioArgs) {
            alert("ERROR!!!!");
            return response;
        }
    });
    return true;
}

function refreshUserInformationLeftArea () {

    var fadeOut = dojo.fadeOut({
        node: "userInformationLeftBarArea",
        duration: 1000
    });

    var fadeIn = dojo.fadeIn({
        node: "userInformationLeftBarArea",
        duration: 2000
    });

    dojo.fx.chain([fadeOut, fadeIn]).play();
}

function showHBLaw () {
    document.body.style.overflow = "hidden";
    dijit.byId("hbLawDialog").show();
}

function hideHBLaw () {
    document.body.style.overflow = "";
    dijit.byId("hbLawDialog").hide();
}

function showTecLaw () {
    document.body.style.overflow = "hidden";
    dijit.byId("tecLawDialog").show();
}

function hideTecLaw () {
    document.body.style.overflow = "";
    dijit.byId("tecLawDialog").hide();
}


function showSearchConsultantFilterOptions () {
    if (dojo.byId("searchConsultantFilterStepTwo").style.display != "") {
        dojo.fx.wipeIn({
            node: "searchConsultantFilterStepTwo",
            duration: 1000
        }).play();
    }
}

function hideSearchConsultantFilterOptions () {
    dojo.fx.wipeOut({
        node: "searchConsultantFilterStepTwo",
        duration: 1000
    }).play();
}

function showDefineServiceCategoriesDialog () {
    document.body.style.overflow = "hidden";
    dijit.byId("defineServiceCategoriesDialog").show();
}

function hideDefineServiceCategoriesDialog () {
    document.body.style.overflow = "";
    dijit.byId("defineServiceCategoriesDialog").hide();
}

function showManageProfileFAQsDialog () {
    document.body.style.overflow = "hidden";
    dijit.byId("manageProfileFAQsDialog").show();
}

function hideManageProfileFAQsDialog () {
    document.body.style.overflow = "";
    dijit.byId("manageProfileFAQsDialog").hide();
}

function showSearchConsultantFAQsDialog () {
    document.body.style.overflow = "hidden";
    dijit.byId("searchConsultantFAQsDialog").show();
}

function hideSearchConsultantFAQsDialog () {
    document.body.style.overflow = "";
    dijit.byId("searchConsultantFAQsDialog").hide();
}

function showConsultantInformationDetailPreview (e) {

    document.body.style.overflow = "hidden";
    dijit.byId("consultantDetailInformationDialog").show();

    //alert("ROW INDEX :: " + e.rowIndex);
    //alert(consultantAreaGrid.get(e.rowIndex, consultantsStore));
    //alert(consultantAreaGrid.getItemIndex(consultantAreaGrid.getItem(e.rowIndex)));

    //alert(consultantAreaGrid.getItem(e.rowIndex).email);
    //cell
    //grid

    document.getElementById("userServicesProvidedString").value = getUserServicesProvidedString();

    dojo.xhrPost({
        url: "ajaxConsultantDetailInformationInclude.php?preview=1",
        form: 'userProfileForm',
        timeoutSeconds: 500000,
        handleAs:"text",
        load: function(response, ioArgs) {
            if(response != "") {
                //Show Success Message
                dojo.byId("consultantDetailInformationDialogArea").innerHTML = response;
            } else {
            //Show Error Message

            }
            return response;
        },
        error: function(response, ioArgs) {
            alert("showConsultantInformationDetailPreview ERROR!!!!");
            return response;
        }
    });

}

function suggestServiceCategoryToBeAdded () {
    showSuggestServiceCategoryToBeAddedDialog();
}

function showSuggestServiceCategoryToBeAddedDialog () {
    dojo.byId('suggestServiceCategorieToBeAddedFormArea').style.display = "";
    dojo.byId('suggestServiceCategorieToBeAddedConfirmationArea').style.display = "none";

    document.body.style.overflow = "hidden";
    dijit.byId("suggestServiceCategorieToBeAddedDialog").show();
}

function hideSuggestServiceCategoryToBeAddedDialog () {
    document.body.style.overflow = "";
    dijit.byId("suggestServiceCategorieToBeAddedDialog").hide();
}

function submitSuggestServiceCategorieToBeAddedForm () {
    document.getElementById("suggestServiceCategorieToBeAddedFormStatusMessage").setAttribute("class", "formProcessingRequestMessage");
    document.getElementById("suggestServiceCategorieToBeAddedFormStatusMessage").setAttribute("className", "formProcessingRequestMessage");
    dojo.byId("suggestServiceCategorieToBeAddedFormStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0' style='margin-left:auto;margin-right:auto;'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:10px;font-weight:bold;'>Your request is being processed...</td></tr></table>";

    if (!dijit.byId("senderEmail").isValid()) {
        dijit.byId("senderEmail").focus();

        document.getElementById("suggestServiceCategorieToBeAddedFormStatusMessage").setAttribute("class", "formErrorMessage");
        document.getElementById("suggestServiceCategorieToBeAddedFormStatusMessage").setAttribute("className", "formErrorMessage");
        dojo.byId("suggestServiceCategorieToBeAddedFormStatusMessage").innerHTML = "Invalid Paramenter(s)";
    } else {
        dijit.byId("resetSuggestServiceCategorieToBeAddedForm").attr("disabled", true);
        dijit.byId("submitSuggestServiceCategorieToBeAddedForm").attr("disabled", true);
        dojo.xhrPost({
            url: "ajaxSendServiceCategoryToBeAddedEmail.php",
            form: 'suggestServiceCategorieToBeAddedForm',
            timeoutSeconds: 500000,
            load: function(response, ioArgs) {
                if(response == '1') {
                    //Show Success Message
                    dojo.byId('suggestServiceCategorieToBeAddedFormArea').style.display = "none";
                    dojo.byId('suggestServiceCategorieToBeAddedConfirmationArea').style.display = "";
                } else {
                    //Show Error Message
                    document.getElementById("suggestServiceCategorieToBeAddedFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("suggestServiceCategorieToBeAddedFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("suggestServiceCategorieToBeAddedFormStatusMessage").innerHTML = "An error has occurred. Please try again.";
                    dijit.byId("resetSuggestServiceCategorieToBeAddedForm").attr("disabled", false);
                    dijit.byId("submitSuggestServiceCategorieToBeAddedForm").attr("disabled", false);
                }
                return response;
            },
            error: function(response, ioArgs) {
                alert("ERROR!!!!");
                return response;
            }
        });
    }
}

function clearSuggestServiceCategorieToBeAddedForm () {
    document.getElementById("suggestServiceCategorieToBeAddedFormStatusMessage").setAttribute("class", "");
    document.getElementById("suggestServiceCategorieToBeAddedFormStatusMessage").setAttribute("className", "");
    dojo.byId("suggestServiceCategorieToBeAddedFormStatusMessage").innerHTML = "";
}











/***** ADMIN PANEL *****/

function showSendRegistryCountsReport () {
    document.body.style.overflow = "hidden";
    dijit.byId("sendRegistryCountsReportDialog").show();
}

function validateAdminLoginFormArea () {

    if (!dijit.byId("adminLogin").isValid() ||
        !dijit.byId("adminPassword").isValid()) {

        document.getElementById("adminLoginFormStatusMessage").setAttribute("class", "formErrorMessage");
        document.getElementById("adminLoginFormStatusMessage").setAttribute("className", "formErrorMessage");
        dojo.byId("adminLoginFormStatusMessage").innerHTML = "Invalid Paramenter(s)";

        dijit.byId("adminLogin").focus();
        dijit.byId("adminPassword").focus();

        return false;
    }

    return true;
}

function resetAdminLoginForm () {
    document.getElementById("adminLoginFormStatusMessage").setAttribute("class", "");
    document.getElementById("adminLoginFormStatusMessage").setAttribute("className", "");
    dojo.byId("adminLoginFormStatusMessage").innerHTML = "";
}

function submitRegistryCountsReporForm () {
    
    document.getElementById("registryCountsReporFormStatusMessage").setAttribute("class", "formProcessingRequestMessage");
    document.getElementById("registryCountsReporFormStatusMessage").setAttribute("className", "formProcessingRequestMessage");
    dojo.byId("registryCountsReporFormStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0' style='margin-left:auto;margin-right:auto;'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:10px;font-weight:bold;'>Your request is being processed...</td></tr></table>";

    if (!dijit.byId("reportReceiverEmail").isValid()) {
        dijit.byId("reportReceiverEmail").focus();

        document.getElementById("registryCountsReporFormStatusMessage").setAttribute("class", "formErrorMessage");
        document.getElementById("registryCountsReporFormStatusMessage").setAttribute("className", "formErrorMessage");
        dojo.byId("registryCountsReporFormStatusMessage").innerHTML = "Invalid Paramenter(s)";
    } else {
        dijit.byId("resetRegistryCountsReporForm").attr("disabled", true);
        dijit.byId("submitRegistryCountsReporForm").attr("disabled", true);
        dojo.xhrPost({
            url: "ajaxAdminSendRegistryCountsReportEmail.php",
            form: 'registryCountsReporForm',
            timeoutSeconds: 500000,
            load: function(response, ioArgs) {
                if(response == '1') {
                    //Show Success Message
                    dojo.byId('adminSendRegistryCountsDialogArea').style.display = "none";
                    dojo.byId('adminSendRegistryCountsConfirmationArea').style.display = "";
                    dojo.byId('reportReceiverEmailConfirmationArea').innerHTML = dijit.byId("reportReceiverEmail").attr("value");
                } else if (response == "EmailDoesNotExistException") {
                    document.getElementById("registryCountsReporFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("registryCountsReporFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("registryCountsReporFormStatusMessage").innerHTML = "Specified email cannot be found.";
                    dijit.byId("resetRegistryCountsReporForm").attr("disabled", false);
                    dijit.byId("submitRegistryCountsReporForm").attr("disabled", false);
                }else {
                    //Show Error Message
                    document.getElementById("registryCountsReporFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("registryCountsReporFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("registryCountsReporFormStatusMessage").innerHTML = "An error has occurred. Please try again.";
                    dijit.byId("resetRegistryCountsReporForm").attr("disabled", false);
                    dijit.byId("submitRegistryCountsReporForm").attr("disabled", false);
                }
                return response;
            },
            error: function(response, ioArgs) {
                alert("ERROR!!!!");
                return response;
            }
        });
    }
}

function clearRegistryCountsReporForm () {
    dijit.byId("registryCountsReporForm").reset();
    dijit.byId("resetRegistryCountsReporForm").attr("disabled", false);
    dijit.byId("submitRegistryCountsReporForm").attr("disabled", false);
    document.getElementById("registryCountsReporFormStatusMessage").setAttribute("class", "");
    document.getElementById("registryCountsReporFormStatusMessage").setAttribute("className", "");
    dojo.byId("registryCountsReporFormStatusMessage").innerHTML = "";
    dojo.byId('reportReceiverEmailConfirmationArea').innerHTML = "";
}

function closeRegistryCountsReporForm () {
    document.body.style.overflow = "";
    dijit.byId("sendRegistryCountsReportDialog").hide();
    dojo.byId('adminSendRegistryCountsDialogArea').style.display = "";
    dojo.byId('adminSendRegistryCountsConfirmationArea').style.display = "none";
    dijit.byId("registryCountsReporForm").reset();
    dijit.byId("resetRegistryCountsReporForm").attr("disabled", false);
    dijit.byId("submitRegistryCountsReporForm").attr("disabled", false);
    document.getElementById("registryCountsReporFormStatusMessage").setAttribute("class", "");
    document.getElementById("registryCountsReporFormStatusMessage").setAttribute("className", "");
    dojo.byId("registryCountsReporFormStatusMessage").innerHTML = "";
    dojo.byId('reportReceiverEmailConfirmationArea').innerHTML = "";
}

function showSendMassCommunicationMessage () {
    document.body.style.overflow = "hidden";
    dijit.byId("sendMassCommunicationMessageDialog").show();
}

function submitMassCommunicationMessageForm () {

    document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("class", "formProcessingRequestMessage");
    document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("className", "formProcessingRequestMessage");
    dojo.byId("massCommunicationMessageFormStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0' style='margin-left:auto;margin-right:auto;'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:10px;font-weight:bold;'>Your request is being processed...</td></tr></table>";

    if (!dijit.byId("massCommunicationTitle").isValid()) {
        dijit.byId("massCommunicationTitle").focus();

        document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("class", "formErrorMessage");
        document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("className", "formErrorMessage");
        dojo.byId("massCommunicationMessageFormStatusMessage").innerHTML = "Invalid Paramenter(s)";
    } else {
        dijit.byId("resetMassCommunicationMessageForm").attr("disabled", true);
        dijit.byId("submitMassCommunicationMessageForm").attr("disabled", true);
        dojo.xhrPost({
            url: "ajaxAdminMassCommunicationMessageEmail.php",
            form: 'massCommunicationMessageForm',
            timeoutSeconds: 5000000,
            load: function(response, ioArgs) {
                if(response == '1') {
                    //Show Success Message
                    dojo.byId('adminSendMassCommunicationMessageDialogArea').style.display = "none";
                    dojo.byId('adminSendMassCommunicationMessageConfirmationArea').style.display = "";
                } else if (response == "EmailDoesNotExistException") {
                    document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("massCommunicationMessageFormStatusMessage").innerHTML = "Specified email cannot be found.";
                    dijit.byId("resetMassCommunicationMessageForm").attr("disabled", false);
                    dijit.byId("submitMassCommunicationMessageForm").attr("disabled", false);
                } else {
                    //Show Error Message
                    document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("class", "formErrorMessage");
                    document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("className", "formErrorMessage");
                    dojo.byId("massCommunicationMessageFormStatusMessage").innerHTML = "An error has occurred. Please try again.";
                    dijit.byId("resetMassCommunicationMessageForm").attr("disabled", false);
                    dijit.byId("submitMassCommunicationMessageForm").attr("disabled", false);
                }
                return response;
            },
            error: function(response, ioArgs) {
                alert("ERROR!!!!");
                return response;
            }
        });
    }
}

function clearMassCommunicationMessageForm () {
    dijit.byId("massCommunicationMessageForm").reset();
    dijit.byId("resetMassCommunicationMessageForm").attr("disabled", false);
    dijit.byId("submitMassCommunicationMessageForm").attr("disabled", false);
    document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("class", "");
    document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("className", "");
    dojo.byId("massCommunicationMessageFormStatusMessage").innerHTML = "";
}

function closeMassCommunicationMessageForm () {
    document.body.style.overflow = "";
    dijit.byId("sendMassCommunicationMessageDialog").hide();
    dojo.byId('adminSendMassCommunicationMessageDialogArea').style.display = "";
    dojo.byId('adminSendMassCommunicationMessageConfirmationArea').style.display = "none";
    dijit.byId("massCommunicationMessageForm").reset();
    dijit.byId("resetMassCommunicationMessageForm").attr("disabled", false);
    dijit.byId("submitMassCommunicationMessageForm").attr("disabled", false);
    document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("class", "");
    document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("className", "");
    dojo.byId("massCommunicationMessageFormStatusMessage").innerHTML = "";
}

function showExportRegistryData () {
    document.body.style.overflow = "hidden";
    dijit.byId("sendMassCommunicationMessageDialog").show();
}

function exportRegistryData () {
    dojo.xhrPost({
        url: "ajaxAdminExportRegistryData.php",
        timeoutSeconds: 500000,
        load: function(response, ioArgs) {
            if(response == '1') {
                //Show Success Message
                dojo.byId('adminSendMassCommunicationMessageDialogArea').style.display = "none";
                dojo.byId('adminSendMassCommunicationMessageConfirmationArea').style.display = "";
            } else if (response == "EmailDoesNotExistException") {
                document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("class", "formErrorMessage");
                document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("className", "formErrorMessage");
                dojo.byId("massCommunicationMessageFormStatusMessage").innerHTML = "Specified email cannot be found.";
                dijit.byId("resetMassCommunicationMessageForm").attr("disabled", false);
                dijit.byId("submitMassCommunicationMessageForm").attr("disabled", false);
            } else {
                //Show Error Message
                document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("class", "formErrorMessage");
                document.getElementById("massCommunicationMessageFormStatusMessage").setAttribute("className", "formErrorMessage");
                dojo.byId("massCommunicationMessageFormStatusMessage").innerHTML = "An error has occurred. Please try again.";
                dijit.byId("resetMassCommunicationMessageForm").attr("disabled", false);
                dijit.byId("submitMassCommunicationMessageForm").attr("disabled", false);
            }
            return response;
        },
        error: function(response, ioArgs) {
            alert("ERROR!!!!");
            return response;
        }
    });
}

/* MANAGE CATEGORIES */

function showManageCategories () {
    document.body.style.overflow = "hidden";
    dijit.byId("sendManageCategoriesDialog").show();
    updateCategoryList();
}

function updateCategoryList () {
    var getCategoryListRequest = getCategoryList();
    getCategoryListRequest.addCallback(function (result) {
        updateCategoryListAnimation(result);
        return result;
    });
    getCategoryListRequest.addErrback(function (result) {
        //enableCreateNewBudgetForm();
        //showCreateNewBudgetFormErrorMessage();
        return result;
    });
}

function getCategoryList () {
    var result = dojo.xhrPost({
        url: "ajaxAdminGetCategoryList.php",
        load: function(response, ioArgs) {
            return response;
        },
        error: function(response, ioArgs) {
            alert("getCategoryList error!");
            return response;
        }
    });
    return result;
}

var tempCategoryList;
function updateCategoryListAnimation (result) {
    tempCategoryList = result;
    var fadeOut = dojo.fadeOut({
        node: "categoryListArea",
        duration: 500
    });

    dojo.connect(fadeOut, "onEnd", setContentOnCategoryListArea);

    var fadeIn = dojo.fadeIn({
        node: "categoryListArea",
        duration: 500
    });

    dojo.fx.chain([fadeOut, fadeIn]).play();
}

function setContentOnCategoryListArea () {
    dojo.byId("categoryListArea").innerHTML = tempCategoryList;
    tempCategoryList = null;
}

function deleteCategory (categoryId) {

    var answer = confirm ("Sure?");
    if (!answer) {
        return true;
    }

    dojo.xhrPost({
        url: "ajaxAdminDeleteCategory.php?id="+categoryId,
        load: function(response, ioArgs) {

            deleteCategoryAnimation(categoryId);
            //updateCategoryList();

            return response;
        },
        error: function(response, ioArgs) {
            alert("deleteCategory error!");
            return response;
        }
    });
    return true;
}

var categoryDeletedId = null;
function deleteCategoryAnimation (categoryId) {

    categoryDeletedId = "category"+categoryId;

    var fadeOut = dojo.fadeOut({
        node: categoryDeletedId,
        duration: 500
    });

    dojo.connect(fadeOut, "onEnd", hideCategoryAreaDeleted);

    dojo.fx.chain([fadeOut]).play();
}

function hideCategoryAreaDeleted () {
    //dojo.byId(categoryDeletedId).style.display = "none";
    
    dojo.fx.wipeOut({
        node: categoryDeletedId,
        duration: 500
    }).play();

    categoryDeletedId = null;
}

function addNewCategory () {

    if (!dijit.byId("categoryName").isValid()) {
        //alert("Invalid Category Name");
        document.getElementById("manageCategoriesFormStatusMessage").setAttribute("class", "formErrorMessage");
        document.getElementById("manageCategoriesFormStatusMessage").setAttribute("className", "formErrorMessage");
        dojo.byId("manageCategoriesFormStatusMessage").innerHTML = "Invalid Category Name";
        return false;
    } else {
        document.getElementById("manageCategoriesFormStatusMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("manageCategoriesFormStatusMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("manageCategoriesFormStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:12px;font-weight:bold;'>Processing Request...</td></tr></table>";
    }

    dojo.xhrPost({
        url: "ajaxAdminAddCategory.php?categoryName="+dijit.byId("categoryName").attr("value"),
        load: function(response, ioArgs) {

            if (response != "AddingNewCategoryException") {

                addCategoryAnimation(response);

                document.getElementById("manageCategoriesFormStatusMessage").setAttribute("class", "formProcessingRequestMessage");
                document.getElementById("manageCategoriesFormStatusMessage").setAttribute("className", "formProcessingRequestMessage");
                dojo.byId("manageCategoriesFormStatusMessage").innerHTML = "Good!";
            } else {
                document.getElementById("manageCategoriesFormStatusMessage").setAttribute("class", "formErrorMessage");
                document.getElementById("manageCategoriesFormStatusMessage").setAttribute("className", "formErrorMessage");
                dojo.byId("manageCategoriesFormStatusMessage").innerHTML = "Request Failed!";
            }

            return response;
        },
        error: function(response, ioArgs) {
            alert("addNewCategory error!");
            return response;
        }
    });
    return true;

}

var categoryAddedId = null;
function addCategoryAnimation (categoryId) {
    
    categoryAddedId = "category"+categoryId;

    newCategoryAddedStructure = getNewCategoryAddedStructure(categoryId);
    
    dojo.byId("categoryListArea").innerHTML = newCategoryAddedStructure + dojo.byId("categoryListArea").innerHTML;

    var wipeIn = dojo.fx.wipeIn({
        node: categoryAddedId,
        duration: 500
    });

    var fadeIn = dojo.fadeIn({
        node: categoryAddedId,
        duration: 1000
    });

    dojo.connect(fadeIn, "onEnd", showCategoryAreaAdded);

    dojo.fx.chain([wipeIn, fadeIn]).play();
}

function showCategoryAreaAdded () {
    //dojo.byId(categoryDeletedId).style.display = "none";
    dijit.byId("categoryName").attr("value", "");
    categoryAddedId = null;
}

function getNewCategoryAddedStructure (categoryId) {
    newCategoryAddedStructure = '<div id="'+categoryAddedId+'" \n\
                                      style="display:none;float:left;padding:5px;text-align:left;background-color:#FFFFFF;border-bottom:1px solid #CCCCCC;">\n\
                                    <div id="categoryLabel'+categoryId+'"\n\
                                         style="float:left;width:370px;overflow:hidden;">\n\
                                        '+dijit.byId("categoryName").attr("value")+'\n\
                                    </div>\n\
                                    <div style="float:left;">\n\
                                        <img src="images/icons/editIcon_1.png"\n\
                                             style="cursor:pointer;" \n\
                                             onclick="javascript:showModifyCategoryForm('+categoryId+')"/>\n\
                                        <img src="images/icons/deleteIcon_1.png"\n\
                                             style="cursor:pointer;padding-left:5px;"\n\
                                             onclick="javascript:deleteCategory('+categoryId+')"/>\n\
                                    </div>\n\
                                </div>';
    return newCategoryAddedStructure;
}

function showModifyCategoryForm (categoryId) {
    dojo.byId("adminManageCategoriesDialogArea").style.display = "none";
    dojo.byId("adminUpdateCategoriesArea").style.display = "";

    dijit.byId("editCategoryName").attr("value", dojo.byId("categoryLabel"+categoryId).innerHTML);
    dojo.byId("editCategoryId").value = categoryId;

    return true;
}

function hideModifyCategoryForm () {
    //updateCategoryList();
    dojo.byId("adminManageCategoriesDialogArea").style.display = "";
    dojo.byId("adminUpdateCategoriesArea").style.display = "none";
    document.getElementById("adminEditCategoryStatusMessage").setAttribute("class", "");
    document.getElementById("adminEditCategoryStatusMessage").setAttribute("className", "");
    dojo.byId("adminEditCategoryStatusMessage").innerHTML = "";
    document.getElementById("manageCategoriesFormStatusMessage").setAttribute("class", "");
    document.getElementById("manageCategoriesFormStatusMessage").setAttribute("className", "");
    dojo.byId("manageCategoriesFormStatusMessage").innerHTML = "";
    dijit.byId("categoryName").reset();

    //alert(dojo.byId("editCategoryId").value);

    highlightCategoryAnimation(dojo.byId("editCategoryId").value);

}

function submitEditCategoryForm () {
    if (!dijit.byId("editCategoryName").isValid()) {
        //alert("Invalid Category Name");
        document.getElementById("adminEditCategoryStatusMessage").setAttribute("class", "formErrorMessage");
        document.getElementById("adminEditCategoryStatusMessage").setAttribute("className", "formErrorMessage");
        dojo.byId("adminEditCategoryStatusMessage").innerHTML = "Invalid Category Name";
        return false;
    } else {
        document.getElementById("adminEditCategoryStatusMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("adminEditCategoryStatusMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("adminEditCategoryStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:12px;font-weight:bold;'>Processing Request...</td></tr></table>";
    }

    dojo.xhrPost({
        url: "ajaxAdminUpdateCategory.php?categoryName="+dijit.byId("editCategoryName").attr("value")+"&categoryId="+dojo.byId("editCategoryId").value,
        load: function(response, ioArgs) {

            //addCategoryAnimation(response);
            
            dojo.byId("categoryLabel"+dojo.byId("editCategoryId").value).innerHTML = dijit.byId("editCategoryName").attr("value");

            if (response == "1") {
                document.getElementById("adminEditCategoryStatusMessage").setAttribute("class", "formProcessingRequestMessage");
                document.getElementById("adminEditCategoryStatusMessage").setAttribute("className", "formProcessingRequestMessage");
                dojo.byId("adminEditCategoryStatusMessage").innerHTML = "Good!";
            } else {
                document.getElementById("adminEditCategoryStatusMessage").setAttribute("class", "formErrorMessage");
                document.getElementById("adminEditCategoryStatusMessage").setAttribute("className", "formErrorMessage");
                dojo.byId("adminEditCategoryStatusMessage").innerHTML = "Request Failed!";
            }

            return response;
        },
        error: function(response, ioArgs) {
            alert("submitEditCategoryForm error!");
            return response;
        }
    });
    return true;
}

function highlightCategoryAnimation (categoryId) {

    var whiteToOrange = dojo.animateProperty({
        node: "category"+categoryId,
        duration: 1000,
        properties: {
            backgroundColor: {
                start:"#FFFFFF",
                end:"#FF6600"
            }
        }
    });

    var orangeToWhite = dojo.animateProperty({
        node: "category"+categoryId,
        duration: 2000,
        properties: {
            backgroundColor: {
                start:"#FF6600",
                end:"#FFFFFF"
            }
        }
    });

    dojo.fx.chain([whiteToOrange, orangeToWhite]).play();
}

/***** MANAGE USER ACCOUNT *****/

function submitSearchUserAccountsForm () {
    var result = dojo.xhrPost({
        url: "ajaxAdminGetUserAccountSearchResults.php",
        form: 'searchUserAccountsForm',
        load: function(response, ioArgs) {
            
            updateUserAccountSearchResultsAnimation(response);

            return response;
        },
        error: function(response, ioArgs) {
            alert("submitSearchUserAccountsForm error!");
            return response;
        }
    });
    return result;
}

var tempUserAccountSearchResults;
function updateUserAccountSearchResultsAnimation (result) {
    tempUserAccountSearchResults = result;
    var fadeOut = dojo.fadeOut({
        node: "userAccountsSearchResultsArea",
        duration: 500
    });

    dojo.connect(fadeOut, "onEnd", setContentOnUserAccountsSearchResultsArea);

    var fadeIn = dojo.fadeIn({
        node: "userAccountsSearchResultsArea",
        duration: 500
    });

    dojo.fx.chain([fadeOut, fadeIn]).play();
}

function setContentOnUserAccountsSearchResultsArea () {
    dojo.byId("userAccountsSearchResultsArea").innerHTML = tempUserAccountSearchResults;
    tempUserAccountSearchResults = null;
}

function showModifyUserAccountDialog (userId) {
    document.body.style.overflow = "hidden";
    dijit.byId("manageUserAccountDialog").show();
    dojo.byId("updateUserId").value = userId;
    dojo.byId("updateUserFirstName").innerHTML = dojo.byId("userFirstName"+userId).value;
    dojo.byId("updateUserLastName").innerHTML = dojo.byId("userLastName"+userId).value;
    dijit.byId("updateUserEmail").attr("value", dojo.byId("userEmail"+userId).value);
}

function resetManageUserAccountForm () {
    dijit.byId("updateUserAccountForm").reset();
    document.getElementById("adminUpdateUserAccountStatusMessage").setAttribute("class", "");
    document.getElementById("adminUpdateUserAccountStatusMessage").setAttribute("className", "");
    dojo.byId("adminUpdateUserAccountStatusMessage").innerHTML = "";
}

function submitUpdateUserAccountForm () {
    if (!dijit.byId("updateUserEmail").isValid()) {
        //alert("Invalid Category Name");
        document.getElementById("adminUpdateUserAccountStatusMessage").setAttribute("class", "formErrorMessage");
        document.getElementById("adminUpdateUserAccountStatusMessage").setAttribute("className", "formErrorMessage");
        dojo.byId("adminUpdateUserAccountStatusMessage").innerHTML = "Invalid Email Format.";
        return false;
    } else {
        document.getElementById("adminUpdateUserAccountStatusMessage").setAttribute("class", "formProcessingRequestMessage");
        document.getElementById("adminUpdateUserAccountStatusMessage").setAttribute("className", "formProcessingRequestMessage");
        dojo.byId("adminUpdateUserAccountStatusMessage").innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr><td style='padding-right:3px;'><img src='images/loaders/smallLoader.gif' /></td><td style='font-family:Verdana;font-size:12px;font-weight:bold;'>Processing Request...</td></tr></table>";
    }

    dojo.xhrPost({
        url: "ajaxAdminUpdateUserAccount.php?email="+dijit.byId("updateUserEmail").attr("value")+"&userId="+dojo.byId("updateUserId").value,
        load: function(response, ioArgs) {

            //addCategoryAnimation(response);

            if (response == "1") {
                document.getElementById("adminUpdateUserAccountStatusMessage").setAttribute("class", "formProcessingRequestMessage");
                document.getElementById("adminUpdateUserAccountStatusMessage").setAttribute("className", "formProcessingRequestMessage");
                dojo.byId("adminUpdateUserAccountStatusMessage").innerHTML = "Good!";

                dojo.byId("userEmailLabel"+dojo.byId("updateUserId").value).innerHTML = dijit.byId("updateUserEmail").attr("value");

            } else {
                document.getElementById("adminUpdateUserAccountStatusMessage").setAttribute("class", "formErrorMessage");
                document.getElementById("adminUpdateUserAccountStatusMessage").setAttribute("className", "formErrorMessage");
                dojo.byId("adminUpdateUserAccountStatusMessage").innerHTML = "Invalid Email. Please try a different email address.";
            }

            return response;
        },
        error: function(response, ioArgs) {
            alert("submitUpdateUserAccountForm error!");
            return response;
        }
    });
    return true;
}

function highlightUserAccountAnimation () {

    userId = dojo.byId("updateUserId").value;

    var whiteToOrange = dojo.animateProperty({
        node: "user"+userId,
        duration: 1000,
        properties: {
            backgroundColor: {
                start:"#FFFFFF",
                end:"#FF6600"
            }
        }
    });

    var orangeToWhite = dojo.animateProperty({
        node: "user"+userId,
        duration: 2000,
        properties: {
            backgroundColor: {
                start:"#FF6600",
                end:"#FFFFFF"
            }
        }
    });

    dojo.fx.chain([whiteToOrange, orangeToWhite]).play();
}

